the above program prints
0012FF60
i was looking to get it to print something with an x in the middle
ex. 0x40tt
the above program prints
0012FF60
i was looking to get it to print something with an x in the middle
ex. 0x40tt
It's pretty basic. All you do is add "0x" in front of the "%p"
i am not asking for you to do my hemework. I am just trying to figure some things out based on my notes and it is not working out. All i want is for someone to explain to me what I am doing wrong.
I do appreciate the help.
i was looking over some notes that i have and all we used was %p without 0X and it was still printing hex.
It could be that that particular implementation adds a "0X".i was looking over some notes that i have and all we used was %p without 0X and it was still printing hex.
Hexadecimal is a number base. The "0x" is just a notation used in languages derived from C. Mathematical notation uses a subscript of "16", other programming languages append a "h". But the representation of the number is hexadecimal, regardless of what is used to denote the base.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
And whilst it is POSSIBLE for the implementation of the C library (the code inside the printf function) to produce something other than hex output, it's unlikely that you'll find such a thing. If someone is interested in the value of a pointer (the address it contains) it makes much more sense to have it in hex, as computer memory addresses are almost always expressed in hex in debuggers etc.
So it is unlikely that the value will be printed as a decimal number for example. Of course, it may not be a plain hex number even then, for example in a 16-bit x86 system (e.g. Turbo C on DOS) a (far) pointer would be XXXX:YYYY where XXXX is the segment base address, and YYYY is the offset, the actual address being (XXXX << 4) + YYYY.
I've also seen some printf() implementations putting 0x in front of the pointer value, and other printf implementations that do NOT put 0x at the front.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.