+ 2

The output is 9 but why?

char *s = "a string"; char *p = s; while(*p++); printf("%d", (int)(p-s));

31st Aug 2020, 4:37 PM
Gujjula Pradeep Reddy
Gujjula Pradeep Reddy - avatar
9 Answers
+ 2
Coder Kitten after while loop p value be "g", so answer should be g-a=5. Am I right?
31st Aug 2020, 5:13 PM
Gujjula Pradeep Reddy
Gujjula Pradeep Reddy - avatar
+ 1
Coder Kitten so, p points to \0 or NULL
31st Aug 2020, 5:42 PM
Gujjula Pradeep Reddy
Gujjula Pradeep Reddy - avatar
+ 1
Answer is 9 right?
31st Aug 2020, 6:00 PM
Gujjula Pradeep Reddy
Gujjula Pradeep Reddy - avatar