Is there any difference between
static int * pn;
and
int static * pn;
Basically I am looking for difference between a pointer pointing to a static variable, and a static pointer pointing to some variable, and not sure whether the above 2 declarations corresponds to them.
a pointer is nothing more than an address, and a pointer variable is just a variable that can store an address. When we store the address of a variable i in the pointer variable p , we say that p points to i . int i, *p = &i; p points to i .
So, THIS pointer is not passed to a static function as an internal parameter. So, a static function does not understand THIS pointer inside its body. If we compile below class, compiler with throw an error i.e. static functions do not have this pointer.
A static pointer can be used to implement a function that always returns the same buffer to the program. This can be helpful in serial communication.
References are used to refer an existing variable in another name whereas pointers are used to store address of variable. References cannot have a null value assigned but pointer can. A reference variable can be referenced by pass by value whereas a pointer can be referenced by pass by reference.
In C there is no difference but the second form is discouraged.
(C99, 6.11.5p1) "The placement of a storage-class specifier other than at the beginning of the declaration specifiers in a declaration is an obsolescent feature"
No, there is no difference. Here, the declaration specifier sequence is static int
or int static
and the order of specifiers in a declaration specifier sequence doesn't matter. Both of your declarations have type "pointer to int".
You can do other weird stuff like int static unsigned const* pn;
if you hate people enough. I wrote a question/answer that covers this topic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With