I have seen,
int *pnum;
int * pnum;
int* pnum;
Are these all the same?
I have seen,
int *pnum;
int * pnum;
int* pnum;
Are these all the same?
Yes, all those three are the same. And in them, that *
is not dereferencing operator, it is part of the type int *
, pointer to int
.
Yes, they are all identical. Whitespace is not significant in C. Which of the three you choose is entirely up to personal preference.
When you declare a variable, like you did in your example, the *
symbol only tells to compiler that this variable is a pointer to the type you've selected.
Example:
int *p;
We have a declaration of a pointer of a integer. How we didn't initialized the pointer, it's value is a random memory address.
Example 2:
int a = 4;
int *p;
p = &a;
*p = 1;
In this example, it's possible to see the assignment of the memory address of a variable to the pointer p
. The symbol &
gets the variable a
memory address. On the last line, we access the memory address associated with the pointer. In other words, the variable a
area.
This is dereference.