Is it the material used that allows the wing to flex or is wing flex caused by the structure of the wing?
The flexing of a structure like an aircraft's wing is generally due to the materials used, but is also related to the nature of the structure itself.
In very simplified form, a wing is a beam that is supported at one end (the fuselage). Any forces such as from aerodynamics that act on the beam will cause it to bend.
All materials have a characteristic way in which they behave when load is applied. This can be expressed as stress (from applied forces) vs. strain (deformation of the material). Once the material reaches the yield strength point, it will be permanently deformed. For stress below this point, though, the material will return to its original shape. The wing can then flex as long as it remains below the yeild strength in all required loads.
Of course there is much more detail to the subject. The whole structure is designed together so that it will be as light as possible, but the amount of flexing is limited to prevent related issues. The wing may need to be made more stiff to prevent flutter. Farhan mentions fatigue, which can also limit the amount the wing may flex. The panels on top and bottom of the wing must also be prevented from breaking or permanently buckling. There are also fuel tank seals that should not be broken. Adding material in the right places can help to spread out the loads, which reduces the stress on the material and therefore reduces the amount of flexing.
The amount a wing can flex is actually a product of the material. The wing requires a specified ultimate strength; with metal, that translates into a given amount of flex. This can be varied within limits, but it is really the material, its stiffness to yield point ratio, and its fatigue properties, that control how much a wing will flex.
Carbon-fiber-reinforced polymer is an extremely strong and light material and has lesser stiffness, and has essentially no fatigue problems. This is beneficial to provider a smoother ride in turbulence. The wing acts like a big spring.
As Federico mentioned, any material can and will flex (to a varying degree). So flexing is because of the material of the wing more than the wing itself.