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 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
"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?
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
> 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.
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
Yes, but *ip -- the location ip points to -- is indistinguishable from
x, at least as far as I can tell. 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
<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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
| |