tags:

views:

131

answers:

3
#define int_p int*
int_p p1,p2,p3; // only p1 is a pointer !

can somebody exlplain why it is so.

+13  A: 

#define is just a textual substitution. The code above is equivalent to

int *p1, p2, p3;

so only p1 is a pointer. You need

typedef int* int_p;

instead.

KennyTM
+2  A: 

Rather than thinking of it like this:

int* (p1, p2, p3);

think of it like this:

int (*p1), p2, p3;

As in, only the symbol with the asterisk in-front of it becomes a pointer, not all of them.

Douglas
+1  A: 
John Bode