Strange Pointer syntax

Could somebody please explain these lines of code as I do not understand the output on the console...

int *l = (int*)1000;
cout << l << endl;

...this prints 1000's hexidecimal equivalent to the console, why is this?
i know that when you cout << l; it gives you the address in memory that the pointer 'l' is pointing to and that when you cout << *l; it gives you the value stored at the address that the pointer is pointing to...
also when i tried
cout << *l; there was a compile error.

Thanks in advance for your help.

.this prints 1000's hexidecimal equivalent to the console, why is this?


Because that's the value of the pointer. All pointers hold a number. That is all they do. What number in this case? 1000. The number you just stored in that pointer.

Read this:

http://cplusplus.com/forum/beginner/54826/

Start at my post about four posts down.
Last edited on
Thanks for that. Read through that thread, I think I have pointers clear in my head now. I guess it was confusing me because I expected to see it's decimal value, but computers don't think like that I suppose.
It just happens to output the hex value by default; when dealing with memory, hex is customary. You can cast it to decimal easily enough.
Topic archived. No new replies allowed.