I am struggling with understanding the correct pointer syntax, various sources seem to be doing it differently.
Which one of these is correct?
int* p = NULL;
int * p = NULL;
int *p = NULL;
and these?
*p = &x;
* p = &x;
Sorry for the beginner question but I can’t seem to find a straight answer.
Does the * goes right after the data type, right before the var name or in between?
This is more a question of grammar, as to which is “correct”, as all are valid.
Think about what the declaration/code describes and join them accordingly.
e.g.
“I want an int pointer called p” implies:
int* p“I want to the
contents pointed to by pto contain the address of x” implies:*p = &xYou want to pick a standard that is easy for others to read, and/or is in popular use, to make the transition into new commercial development sites easier. They will all have similar coding standards.