Considering pch, pshort, pdouble declared as pointers to char ,short int ,double respectively, what would be the arrangement if the three variables were arranged according to their size ?
Considering pch, pshort, pdouble declared as pointers to char ,short int ,double respectively, what would be the arrangement if the three variables were arranged according to their size ?
The facetious answer is you don't know. char, short, and double could all be the same size, and char*, short*, and double* could all be different sizes!
sizeof(char) is 1 by the standard. You can't have anything smaller than that, so it makes sense to put char first.
But short int could be the same size as a long int: the standard only specifies minimum ranges. And either could be larger than a double.
Normally a double weighs in at 64 bit, and a short 16 or 32 bits.
The parsimonious answer is char, short, double.
As for pointers, the standard allows sizeof(char*), sizeof(short*), and sizeof(double*) to all differ.
Pointers to different types may have different sizes, although on most modern platforms they are all the same size (32 bits on x86, 64 bits on x86_64).
The requirements1 are:
char and pointers to void have the same size and representation;struct types all have the same size and representation;union types all have the same size and representation;sizeof (int*) == sizeof (const int *))Pointer variables are usualy 64 bits on machines that can do 64 bit arthmetic, because that allows the machine to handle more than 2^32(4 billion, or 4 gigabytes) of RAM. In machines that can't handle 64 bit arithmetic, long pointers, which are slower and actually two poimters put together, that treat each maximum amount of RAM as an index in an array, must be used. Consequentially, long pointers are slower than regular pointer.
EDIT Bethsheba reminded me, in a comment below that the pointer will usually not be 64 bits when in a register, but will usually be padded to 64 bits in memory for performance reasons (so, treat it as 64 bits).