Is a non-void pointer in C only cares about the memory space from its address to the address that the memory space is suitable for the type or ...?
Example:
typedef struct {...} A;
// the allocated memory space is much larger than sizeof(A)
A* temp = (A*) malloc(sizeof(A) + 256 * 256);
char* charPointer = (char*) temp;
charPointer += sizeof(A);
temp = (A*) charPointer;
In the last line, is temp
still point to the new "A variable"? (seems an array of A allocated)
Update:
Does the cast in temp
declaration & initialisation turns the memory space into an array of A
, or memory space has no "type", the temp
takes first (size: sizeof(A)
) memory space to store A
variable, and the rest of memory space did nothing?