Probably a stupid question

Hey all,

I'm trying to get my thought around pointers, now I have a very easy question. When defining a pointer does: int* p or int *p both result in a pointer?

Thanks in advance!
Yes, all three definitions

int* p;
int *p;
int * p;

define an object of the same type that is a pointer to int.
They both mean the same thing. It might be a matter of debate as to which is the preferred style.

However, consider this:
int* p, q;

This means the same as
int *p;
int q;

Thus it may be better to keep the * together with the variable name, or else one might be misled into thinking 'int*' means everything which follows is a pointer, which is not the case.
Thanks, professor uses both so I got a bit confused..
Wait until you get to const pointers, or pointers to const data. :)
they are tough to bend your head around, i am just getting it a month later

This is the sort of thing we were talking about in the other thread. Don't make posts that are not helpful.

When someone posts a programming question, they are interested in answers or helpful hints - not useless comments.
I personally stick the * with the data type:

int* ptr;

I just don't stick multiple declarations on one line. I think it's easier to scan through and see that this a pointer to an int.
whaat!? thats moral support ideas man, beginners are most likley to give up unnecessarily when it comes to pointers, i know the teaching method, telling him he will get it will keep him persistent, and your comment is no better, infact, its worse :P
Last edited on
Topic archived. No new replies allowed.