What I know about the '&' operator, it returns the base address of the operand in memory.
Imagine the following scenario (as on my machine):
- sizeof (int) = 4 bytes
- sizeof (float) = 4 bytes
- sizeof (char) = 1 byte
Now, if I write something like this:
void main() {
int i = 5411;
int *ip = &i;
char *c = &i;
printf("%d",*ip);
printf("%c",*c);
}
The first printf () should give me 5411. Speaking of the second printf (), the base address I contain is 10101001 (the most significant bit is 8 bits = 1 byte for a pointer of type char). Therefore, * c should give me 169, which when converted to% c is an invalid character.
But the compiler gives me "#" or some other valid output. Why is this so? Any inputs?
EDIT (taken from author's comment on one of the answers):
, .
: = 5411