Pass struct by reference in C

后端 未结 5 661
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-13 02:28

Is this code correct? It runs as expected, but is this code correctly using the pointers and dot notation for the struct?

struct someStruct {
 unsigned int t         


        
5条回答
  •  生来不讨喜
    2020-12-13 03:05

    Yes, that's right. It makes a struct s, sets its total to 5, passes a pointer to it to a function that uses the pointer to set the total to 4, then prints it out. -> is for members of pointers to structs and . is for members of structs. Just like you used them.

    The return values are different though. test should probably be void, and main needs a return 0 at its end.

提交回复
热议问题