473,704 Members | 2,854 Online

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
Jul 23 '05 #1
9 1743
JS wrote:
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.

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #2

"Ioannis Vranos" <iv*@remove.thi s.grad.com> skrev i en meddelelse
news:1110923535 .5379@athnrd02. ..
JS wrote:
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.

ok so the value of x and *ip is both 2 if int x = 2 right?
Jul 23 '05 #3
JS wrote:
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
Jul 23 '05 #4
JS wrote:
ok so the value of x and *ip is both 2 if int x = 2 right?

Right.

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #5
> 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.
Jul 23 '05 #6
codigo wrote:
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.

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #7
Yes, but *ip -- the location ip points to -- is indistinguishab le from
x, at least as far as I can tell.

Jul 23 '05 #8
ev****@gmail.co m wrote:
Yes, but *ip -- the location ip points to -- is indistinguishab le from
x, at least as far as I can tell.

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

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #9

<ev****@gmail.c om> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Yes, but *ip -- the location ip points to -- is indistinguishab le from
x, at least as far as I can tell.

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

-Howard
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.