c - Is there any significant difference between `->` and `.` for accessing struct members? -


For people familiar with C and its nuances it can be very too , I do not I am familiar with either and can not tell that -> or . There is a important difference in reaching a member of a strat using .

Like I have struct my_struct :

  struct my_struct {int x; Int y; }; Struct my_struct grid;   

Does this make a difference beyond the different syntax, do I via struct my_struct grid member of x Access the grid .x or grid-> x ? And if someone makes a difference, who can I like?

Tried searching Google / SO, but I did not tell anything which was a favorite, if any, method. Both look correct, but I can not help but one of the more specific uses ( - & gt; ) is the case.

It depends on how the structure is declared if we have the actual straight variable , Then use . If we have an indicator for a structure, then use -> :

  struct my_struct * s = ...; S- & gt; X = 5; Printf ("% d \ n", s-> x); Struct my_struct s2 = ...; S2.x = 4; Printf ("% d \ n", s2.x);    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -