Question about pointers

J

JS

I have the following:

int x = 2;

int *ip;

ip = &x;


now as I understand *ip equals 2.


Is it possible to say that *ip equals a value and & is the adress for that
value?

JS
 
I

Ioannis Vranos

JS said:
I have the following:

int x = 2;

int *ip;

ip = &x;


now as I understand *ip equals 2.


Is it possible to say that *ip equals a value and & is the adress for that
value?


ip is a variable that stores the memory address of variable x.

When you dereference ip like this: *ip, you access x.
 
V

Victor Bazarov

JS said:
I have the following:

int x = 2;

int *ip;

ip = &x;


now as I understand *ip equals 2.


Is it possible to say that *ip equals a value and & is the adress for that
value?

'&' is an operator. It is not an address of anything. Was it a typo?

Anyway... *ip designates an object. The original name of that object is
'x'. The value of 'x' and, consequently, of *ip, is 2, since they both
designate the same object.

V
 
J

JS

Ioannis Vranos said:
ip is a variable that stores the memory address of variable x.

When you dereference ip like this: *ip, you access x.

ok so the value of x and *ip is both 2 if int x = 2 right?
 
C

codigo

ok so the value of x and *ip is both 2 if int x = 2 right?
A clear distinction needs to be made here. The two variables are one and the
same entity. It matters not which is modified or initialized. The correct
statement would be that *ip is x, regardless of what value it happens to
hold.
 
I

Ioannis Vranos

codigo said:
A clear distinction needs to be made here. The two variables are one and the
same entity. It matters not which is modified or initialized. The correct
statement would be that *ip is x, regardless of what value it happens to
hold.


ip and x are *two* different objects with a separate memory address each
one. ip is an int pointer variable, that is, it stores memory addresses
of int variables, while x is an int variable.
 
E

evaned

Yes, but *ip -- the location ip points to -- is indistinguishable from
x, at least as far as I can tell.
 
I

Ioannis Vranos

Yes, but *ip -- the location ip points to -- is indistinguishable from
x, at least as far as I can tell.


ip dereferenced, accesses x. We use very accurate terminology in clc++. :)
 
H

Howard

Yes, but *ip -- the location ip points to -- is indistinguishable from
x, at least as far as I can tell.

That is, so long as ip isn't changed to point elsewhere!

-Howard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top