4 ms·
He's wrong. A pointer, at least in C, is not a number, and saying that it is just causes confusion. Pointers have some of the same properties as numbers (speci
by _kst_ 14y ago
He's wrong. A pointer, at least in C, is not a number, and saying that it is just causes confusion.
Pointers have some of the same properties as numbers (specifically integers). In particular, you can do arithmetic on them -- but only in a very restricted way. You can add or subtract an integer to a pointer, yielding a pointer, and you can subtract a pointer from a pointer, yielding an integer.
Most current architectures have a single monolithic addressing space, and pointers can be treated as indices into that address space, treated as a very large array. But the C standard is carefully written to permit other memory models.
For example, pointers to distinct objects cannot meaningfully be subtracted or compared, except for equality or inequality.
Sure, a pointer is represented as a sequence of bits, and that sequence of bits can be treated as an integer -- but the mapping is unspecified. Similarly, a floating-point representation can be mapped onto an integer representation; that doesn't mean that the integer value 1069547520 will help you understand the floating-point number 1.5.
A pointer is a pointer. If you want to understand how pointers work, learn about pointers.
See also sections 4 and 6 of the comp.lang.c FAQ at http://www.c-faq.com/ http://www.c-faq.com/.