a simple one....try this...
2 posters
Page 1 of 1
a simple one....try this...
consider this code....
now given that ASCII value of '1' is p.... what does this output... answer in terms of p....
try this without actually running the code....
- Code:
main()
{
char *p = "1111" ;
printf("%d\n",*(int *)p) ;
}
now given that ASCII value of '1' is p.... what does this output... answer in terms of p....
try this without actually running the code....
vijay- Posts : 6
Join date : 2008-08-18
i think this is it......
"1111" is a string, not a decimal value 1111. You cannot convert it to an decimal simply by forcing a 'reinterpret' cast. All that will do is take the bit pattern used to represent the string and interpret it as an integer. The bit pattern for 1111 decimal is not the same as that for "1111" ASCII.
I am not sure what you mean by 'in terms of "p"', but u will get o/p 825307441 which is decimal equivalent of
ASCII value of string "1111"
I am not sure what you mean by 'in terms of "p"', but u will get o/p 825307441 which is decimal equivalent of
ASCII value of string "1111"
gajju- Posts : 2
Join date : 2008-08-10
Re: a simple one....try this...
yeah..output is as what u said....and
825307441 = (256^3) * 49 + (256^2) * 49 + (256) * 49 + 49
"p" is ASCII value of '1' i.e = 49.... its not the character pointer "p" there... i forgot to mention that....
char *p = '1' '1' '1' '1'
so when u read a integer located at "p" as *(int *)p... u r going to read 4 bytes from "p" as an integer stored in binary... and thats
the output...hope i'm clear....
825307441 = (256^3) * 49 + (256^2) * 49 + (256) * 49 + 49
"p" is ASCII value of '1' i.e = 49.... its not the character pointer "p" there... i forgot to mention that....
char *p = '1' '1' '1' '1'
so when u read a integer located at "p" as *(int *)p... u r going to read 4 bytes from "p" as an integer stored in binary... and thats
the output...hope i'm clear....
vijay- Posts : 6
Join date : 2008-08-18
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum