0

So, I see pointers defined in many different ways but I never quite understood what the difference was. Could someone explain it to me?

Examples:

int * a; int* a; int *a

That second one may or may not be actual C++ but I've seen it done in all those ways.

3
Contributors
3
Replies
24
Views
3 Years
Discussion Span
Last Post by pars99
1

This is the syntax for the declaration of a pointer to an integer, I guess the most common is int * a;
What is sometimes confusing is that dereferencing a pointer uses practically the same syntax int i = *a;
Here i will contain the integer value that is stored in the adress pointed to by pointer a.

1

It doesn't really matter where you put the space in the syntax, the compiler doesn't care. The examples you posted are all acceptable and correct. It's only a matter of programming style -- however you wish to do it.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.