473,704 Members | 2,854 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 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
JS

"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.

Similar topics

16
2015
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 of the destructor. So I think I am somehow using delete incorrectly, but I'm not sure exaclty what I'm doing wrong. I'd apprecitate any clarification and suggestions for rewriting the below properly.
11
1784
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 understand why. Can some guru help to enlighten me? Thank you. // I created an array of pointers to object pointers: Object ** obs = new Object * ;
27
3399
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 as ff: typedef struct { float *data ; int count ;
20
6559
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 area of ram that's not reserved by the program. Accessing memory through such pointer is likely to result in core dump (memory access violation)"
9
1949
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 some data types defined thus: typedef enum { ONE ,
9
5266
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 w1 and w2 make up the first string and, w3 and w4 make up the second string. I do not want to allocate memory, then put the words together to create a string only to facilitate strcmp() comparison. My question; Does anyone know how to get the...
21
1837
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 object pointered by any pointer will be deleted and only be deleted once?
3
1618
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 work here)? The conversion is done for this purpose: I have an std::map<std::string, Base*>. I want to "associate" Derived* handles to the stored Base* so when Base* in the map changes (ie points another address), the Derived* handle outside of...
21
1547
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, but the compiler complains that the function is of the wrong type for qsort. How can I cast the function pointer to shut off the warning? A: The conversions must be in the comparison function, which must be declared as accepting ``generic...
17
2319
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 same as its address. The second one simply depends on a term that is not well-defined. Most people consider the type to be an important part of the notion of
0
9271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9025
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8975
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5930
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4438
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4699
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3134
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2478
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.