note.
g is an inside note and therefore it stays static.
b, the third note of g major (b which is also the leading note in a c major scale) is the leading tone of c major and is clearly taking us back to c (the first note of the scale).
d is the second note of c major and as an outside note it wants to go to e in this case.
we can now see how g major leads us to c major. g major however could function also differently and lead us to some other scale so composer found a way to distinguish the chord as part of the c major 