Depending on the time of day, the balance of photosynthesis to respiration will create different concentration gradients which causes gases to diffuse in or out
These gases are exchanged with the atmosphere in the mesophyll layer of the leaf
Plants ned CO2 for photosynthesis and also oxygen for respiration, both processes produce the other as a waste product