Hacker News new | ask | show | jobs
by csboyer 2115 days ago
The pointer variable does not contain the type - it only stores the address. Sizeof will return whatever the machine address width is.

The type is implicitly stored as the pointers type. Casting a pointer can change a piece of memory to be interpreted as any type you want. Although the cast might not make logical sense or may even caused undefined behavior in C.

Pointer arithmetic works off of whatever the current type is, as the compiler needs to know how to the memory offsets.

1 comments

I actually meant that pointer type is also important to understand the concept. I may not have stated it well. Yes, it does not store the type of the variable it points to but type of the pointer matters and it is significant because many operations depends on it.
C beginner here. I think you stated it well : "and a type" The post you responded to on the contrary misses your point that in memory a pointer is a variable that stores both an address and type information to what it points to.
No, it does not. The compiler knows the pointer type so that it can generate correct assembly, but the pointer type is not something stored in memory past the compilation phase.