difference between int* p and int *p declaration

This tip submitted by omprakash mishra on 2006-03-13 13:43:38. It has been viewed 33877 times.
Rating of 6.5 with 510 votes



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;



More tips

Help your fellow programmers! Add a tip!