Need help on pointer/address

If aPtr is an integer pointer, then &(*aPtr) has the same value as aPtr. (True/False)
Can somebody explain what this means?
Thanks.

& is the Address of operator...so

int *nPtr; // Integer Pointer
int someInt;

nPtr = &someInt; // this integer pointer points to the memory address of someInt

* is the dereference operator...evaluating the contents of the memory location held by your pointer...so

int newInt = *nPtr; // this new integer is now equal to the value pointed to by nPtr;

the following code works just fine for me

1
2
3
4
5
6
7
8
9
10
int main()
{
	int newInt = 4;
	int *nPtr = &newInt;
	int *nPtr2 = &(*nPtr);
	
	std::cout << *nPtr2 << '\n';

	return(0);
}
Last edited on
I'm still not getting the part &(*aPtr).
Can you explain more indepth?
Thanks for the reply.
One operation, reverses the other...

int *nPtr2 = &(*nPtr) is the same as int *nPtr2 = nPtr

there is a difference in a * character when it comes after a Type name such as int or char or float etc...that signifies a variable is a pointer.

the * elsewhere is used to obtain the contents of the pointer...rather than the simple memory address
What if it is like this *(&nPtr) would it be the same?
this would evaluate to the dereferenced value at the address of the pointer.

if nPtr is a pointer...it doesn't make much sense to get the address of an address...you see?

but i think this will evaluate to 4 instead of some memory address
assuming we are still talking about the above code
Topic archived. No new replies allowed.