hello friends
the result is not 5 why this?Code:int main()
{
char*p;
p="23";
printf("%c",p[0]+p[1]);
}
Printable View
hello friends
the result is not 5 why this?Code:int main()
{
char*p;
p="23";
printf("%c",p[0]+p[1]);
}
Because you never allocated memory for your pointer, and you can't use the assignment operator after the initial definition when dealing with C-string, you would need to use the strcpy() function.
Jim
I think jim's been drinking! :)
"23" is shorthand for the char array'2' is a number that is dependent on the character set of the system. In ascii, it is the number 50 (decimal).Code:{'2','3','\0'}
'3' in ascii is 51.
50 + 51 is 101, which in ascii is the character 'e'.