electric
2012-08-09 11:02:56 UTC
What I want to ask you is,since "ptr_char" is a character pointer, isn't the program supposed to interpret only the SINGLE byte pointed to by the character pointer?Since we know character pointers consider 1 bytes.Why is then in my code snippet, a whole 4 bytes after the addressed pointed by the character pointer are being considered?I mean, my code outputs "35,#" , that is, for the "%d" format specifier, it reads the whole 4 bytes representing the integer instead of the first byte of the integer.Similarly, for the "%c" format specifier , it considers the ASCII value represented by the 4 bytes (ie 35) instead of the first byte alone.
Why is this happening?I mean, isn't a character pointer supposed to consider only the single byte pointed by it, just like an integer pointer is supposed to consider the 4 bytes after the address it points to?Though I am incoherent , I am sure you know what I mean to ask.So kindly answer this one.Thanks
#include
int main()
{
int sum[3]={13,25,35};
int *ptr_int=sum;
char *ptr_char;
ptr_char=(char *)ptr_int;
printf("%d , %c",*(ptr_char+8),*(ptr_char+8));
}
OUTPUT: 35,#
///Please don't ignore this question if you are Henni, Ratchetr,Husoski,Oops,MrMe,Peteams,Laurence,Jonathan............