difference between int* p and int *p declaration

0 votes
51 views
asked Dec 20, 2013 in C++ by John

1 Answer

0 votes
answered Dec 20, 2013 by admin (8,135 points)

Be careful when declaring a pointer variable to any type--for instance if you are going to declare a pointer to integer with statement 

int* p; 

and you decide to declare another pointer to integer, you may declare it like this way : 

int* p, q; 

since here the * is associated to the int you may think that what ever variable you declare is a pointer variable. But q is actually an ordinary non-pointer variable here. 

so be careful! You have to write this as: 

int *p, *q; 

Or better yet, just use two lines of code: 

int *p; 
int *q;

...