Jiew Meng Jiew Meng - 2 months ago 9
C++ Question

Declaring more than 1 pointer in a single declaration

Reading accelearated C++: theres a discussion on whether

int* i
or
int *i
should be used. And that
int* p, q
is actually
int (*p), q
. So I suppose
q
is just an int? (not a pointer)? Then is it possible to declare a bunch of pointers?

I don't suppose
int *p, *q
will work?

Answer

I don't suppose int *p, *q will work?

It will, test it. That's correct way to do this.

Another option, to avoid such confusion, is to declare them separately

int* p;
int* q;

So I suppose q is just an int

in int* p, q - yes, it is int, and not a pointer.