size of an integer pointer

This is a discussion on size of an integer pointer within the C Programming forums, part of the General Programming Boards category; I have a simple code here
Code:
int i, *p;
printf("sizeof i =%d, size of pointer =%d", sizeof(int), sizeof(p));
I ...

in that case(64 bit processor) should not we get 8 bytes for sizeof(int) also?

As explained, not necessarily.

"int" is a "natural integer" to the processor. On for example x86-64, handling 32-bit integers is "natural" to the processor - it is in fact often 1 byte shorter in machine code to do 32-bit operations than 64-bit operations. Further, since MOST of the time, 32-bit integers are entirely sufficient for the calculations where "int" is being used, it serves no real purpose to extend the integer type to 64-bit - the integers would just take up twice as much space without any real benefit to anything or anyone (and form slightly bigger code to make it worse). It is also worth noting that the x86-64 architecture automatically extends 32-bit math operations so that the result is consistant throughout the 64 bits, e.g. subtracting one from zero will form a 64-bit value of -1, even if it's done in 32-bit math.

In a 64-bit machine where accessing 32-bit integers would be significantly slower/generate noticeably more code or otherwise cause performance problems, then choosing int as 64-bit would definitely make sense.

The C standard makes no real guarantees about the size of int - it has a minimum size (I think of being able to hold -32768 .. 32767), but there's no statement of it's maximum size. long int must not be SMALLER than int, but can be the same.

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell