+ 1
Help me stuck in pointer [C program] why *s=115 showing while s=4210688
Int main (){ Char *s="solo"; Printf("%d",*s); Printf("%d",s); Char *p=s; Printed("%c%c", *(p+3),s[1]); Return 0; }
2 Answers
+ 2
When a char is printed by an integer format specifier, it's ASCII value is printed.
*s is a char i.e., 's' and ASCII value of 's' is 115. (try this: printf("%d", 's');)
Now why printf("%d", s); gives 4210688. It is because s is a pointer and it stores an address. 4210688 was the address stored by the pointer s.
string:
's' 'o' 'l' 'o'
4210688 4210689 4210690 4210691
+ 1
ļ½ļ½ļ½ļ½ļ½ļ½ļ½ well explained answer thank you