473,322 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Question about pointers

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
Jul 23 '05 #1
9 1718
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
JS

"Ioannis Vranos" <iv*@remove.this.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 indistinguishable from
x, at least as far as I can tell.

Jul 23 '05 #8
ev****@gmail.com wrote:
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++. :-)

--
Ioannis Vranos

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

<ev****@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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
Jul 23 '05 #10

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

Similar topics

16
by: cppaddict | last post by:
Hi, I am deleting some objects created by new in my class destructor, and it is causing my application to error at runtime. The code below compiles ok, and also runs fine if I remove the body...
11
by: DamonChong | last post by:
Hi, I am new to c++. I recently spend an enormous among of time troubleshooting a seeminly innocuous piece of code. Although I narrow down this piece of code as the culprit but I don't...
27
by: Susan Baker | last post by:
Hi, I'm just reading about smart pointers.. I have some existing C code that I would like to provide wrapper classes for. Specifically, I would like to provide wrappers for two stucts defined...
20
by: __PPS__ | last post by:
Hello everybody in a quiz I had a question about dangling pointer: "What a dangling pointer is and the danger of using it" My answer was: "dangling pointer is a pointer that points to some...
9
by: Alfonso Morra | last post by:
Hi, I am having some probs with copying memory blocks around (part of a messaging library) and I would like some confirmation to make sure that I'm going about things the right way. I have...
9
by: Steven | last post by:
Hello, I have a question about strcmp(). I have four words, who need to be compared if it were two strings. I tried adding the comparison values like '(strcmp(w1, w2) + strcmp(w3, w4))', where...
21
by: Bo Yang | last post by:
As long as I write c++ code, I am worry about the pointer. The more the system is, the dangerous the pointer is I think. I must pass pointers erverywhere, and is there a way to ensure that every...
3
by: Filimon Roukoutakis | last post by:
Dear all, assuming that through a mechanism, for example reflexion, the Derived** is known explicitly. Would it be legal (and "moral") to do this conversion by a cast (probably reinterpret would...
21
by: Chad | last post by:
At the following url http://c-faq.com/lib/qsort2.html, they have the following Q: Now I'm trying to sort an array of structures with qsort. My comparison function takes pointers to structures,...
17
by: Ben Bacarisse | last post by:
candide <toto@free.frwrites: These two statements are very different. The first one is just wrong and I am pretty sure you did not mean to suggest that. There is no object in C that is the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.