Help please

I am new to C++. I have a confusion about this:

What's the difference between int *a = b; and int *a = &b;
Assuming that b is an int,
You'd get an error if you do int *a = b;.
This is because you are trying to assign an int value to an int pointer.

int *a = &b;
The code above assigns the memory address of b to a. Therefore a will now point to the memory address of b (since a is a pointer).

Pointers are explained in-depth here: http://www.cplusplus.com/doc/tutorial/pointers/
Last edited on
*a = b is assigning a ? value to an int pointer.
*a = b is assining The memory address of &b to *a.
Topic archived. No new replies allowed.