Today, I learn that we should use int* x
to define a pointer variable than int *x
. Why?
Following is the way, we can define a variable in C.
int x = 3;
printf("%d\n", x); // prints "3".
If we prefix this x
variable with &
as &x
, it'll returns the address of given variable. The type of this return address is int*
meaning address of integer and *
as pointer to that address.
int* address = &x;
To print the address, we can use %p
as placeholder.
printf("%p\n", address);
Notice, here I wrote address
and not *address
. Because, *
is not part of address
variable name than part of type.
Labels: c