473,396 Members | 2,154 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,396 software developers and data experts.

Simple Pointer Question


Hi all,

I have got a pointer question. I was told that a pointer is a variable
holding a memory address.

SO:

...

//I: a variable holding a memory address

unsigned char U8 = 0xFFFF;

//II: a variable holding a memory address

unsigned char* pU8 = (unsigned char*)0xFFFF;

printf("U8 = %X \n",U8);

printf("pU8 = %X \n",pU8);

...

Output:

U8 = FF

pU8 = FFFF

I understand that U8 = FF (1 byte). I do not understand why pU8 = FFFF
(2 bytes), there is only 1 byte storage, so where is this number
(FFFF) stored?
--
Posted via http://dbforums.com
Jul 19 '05 #1
4 6259

"trustron" <me*********@dbforums.com> wrote in message
news:35****************@dbforums.com...

Hi all,

I have got a pointer question. I was told that a pointer is a variable
holding a memory address.

<<snip wrong stuff>>

You were told wrong. A pointer is a variable of type pointer that holds an
address.
A type defines the size of area in memory used to store a value and the
encoding of that value. In the case of a pointer it is an area at least
large enough to store an address for the machine you are on and the encoding
is the address of another area of memory. It is NOT just bits that look like
an address.
There are operations defined for pointer type that only apply to pointer
variables; like the dereferencing operator and pointer arithmetic.
--
Gary
Jul 19 '05 #2
trustron wrote:
..

//I: a variable holding a memory address

unsigned char U8 = 0xFFFF;

//II: a variable holding a memory address

unsigned char* pU8 = (unsigned char*)0xFFFF;
printf("U8 = %X \n",U8);
printf("pU8 = %X \n",pU8);

Output:

U8 = FF

pU8 = FFFF

I understand that U8 = FF (1 byte). I do not understand why pU8 = FFFF
(2 bytes), there is only 1 byte storage, so where is this number
(FFFF) stored?

pU8 is a memory address (i.e. a pointer). Assigning it to FFFF is
undefined - however on most moderm architectures it is a 32 bit number.
(hence why you are able to assign 0x0000ffff).

Jul 19 '05 #3

"Gary Labowitz" <gl*******@comcast.net> wrote in message
news:E6********************@comcast.com...

I have got a pointer question. I was told that a pointer is a variable
holding a memory address.


You were told wrong. A pointer is a variable of type pointer that holds an
address.


He was not told wrong* - a pointer *is* a variable holding a memory address.
(At least it's supposed to - it could well be argued that 0 is not a memory
address.) He simply wasn't given enough information.

*I've never seen a newsgroup where people are so eager to tell other people
how wrong they are.....
Jul 19 '05 #4
jeffc wrote:
>
> I have got a pointer question. I was told that a pointer is a variable
> holding a memory address.


You were told wrong. A pointer is a variable of type pointer that holds an
address.


He was not told wrong* - a pointer *is* a variable holding a memory address.
(At least it's supposed to - it could well be argued that 0 is not a memory
address.) He simply wasn't given enough information.


There are at least four fundamentally different flavors of pointers in
C++: regular pointers to data, pointers to regular functions, pointers
to member functions, pointers to data members. In general case some of
these kinds of pointers will hold a lot more than just a "memory
address". For this reason, in general case it is not correct to say that
a pointer "is a variable holding a memory address".

A pointer holds an address, all right (keeping in mind that in C++
terminology term "address" is a synonym for term "pointer"). Once you
start qualifying that term "address" with such undefined modifiers as
"memory" (as in your "memory address"), you start walking on thin ice.
Needlessly, I might add.

--
Best regards,
Andrey Tarasevich

Jul 19 '05 #5

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

Similar topics

4
by: Asif | last post by:
Hi there, I have been trying to understand the behaviour of char (*pfn)(null) for a couple of days. can some body help me understand the behaviour of char (*pfn)(null) in Visual C++ environment?...
22
by: lokman | last post by:
Hi, In the following code, can someone tell me the difference between *p++ and p++ ? I can see both achieve the same result. Thanks a lot !
7
by: cppaddict | last post by:
The following code compiles but errors at runtime: int main() { std::string* str; str->insert(0,"test"); std::cout << *str; } Why does this not work? How can I fix it?
5
by: overbored | last post by:
I can do this: int asdf; int* zxcv = asdf; but not this: int asdf; int** zxcv = asdf;
73
by: Claudio Grondi | last post by:
In the process of learning about some deeper details of Python I am curious if it is possible to write a 'prefix' code assigning to a and b something special, so, that Python gets trapped in an...
24
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have...
11
by: Sensei | last post by:
I'm sorry to always bother you guys on simple C topics... but here again I go :) What does the standard C99 (and if you have knowledge, pre-C99 also) say about the behavior of realloc() on...
4
by: Jeffrey Spoon | last post by:
Hello, I am trying to make a simple function that returns a pointer to another function. In my header file I've declared my function pointer: void (*pStateFunction) (void); //assume the function...
3
by: nembo kid | last post by:
I have an issue with a simple function that has to make a linear search for a key into an array. If the key is found in the array, the function it has to return 1 to the caller and pass array...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.