Help me stuck in pointer [C program] why *s=115 showing while s=4210688 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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; }

28th Jun 2021, 2:48 AM
Nitin Bisht
Nitin Bisht - avatar
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
28th Jun 2021, 4:37 AM
abhinav
abhinav - avatar
+ 1
abhinav well explained answer thank you
28th Jun 2021, 6:30 AM
Nitin Bisht
Nitin Bisht - avatar