One little question
What is the difference(if any??) on those 3:
int * p;
is there any difference?
I tried this
and they all output 5, so, I'm curious.
int n1 = 5;
p1 = &n1;
cout << *p1 << endl;
int n2 = 5;
p2 = &n2;
cout << *p2 << endl;
int * p3;
int n3 = 5;
p3 = &n3;
cout << *p3 << endl;
> is there any difference?
No - they're all the same to the compiler.
> int* p;
Except this suggests a precedence which isn't true, which is more likely to affect the reader of the code.
p is a pointer to an int, q is just an int.
makes it look more likely that p and q are both pointers (which would be wrong).
It's amazing how many programmers use this one. Like Salem, I also prefer:
Or you could use the formatting scheme suggested by galmca. By completely omitting all whitespace, you reduce the size of a source code file, making it faster to transmit. Consider the truly elite form: int*p;
Of course, I merely suggest this in jest. ;) Using the form Salem suggested has kept me from decieving myself several times. It's a good habit to acquire.