+ 6

Why output is llo.

This is c code. #include<stdio.h> int main() { char *x="hello"; x+=2; printf("%s",x); return 0; } //Output=llo

3rd Nov 2019, 3:01 AM
Maninder $ingh
Maninder $ingh - avatar
4 Answers
+ 10
char *x is pointer to "hello" so it refers to the starting position of string and when we increment it, then it starts pointing to 2nd char i.e. l.
3rd Nov 2019, 3:21 AM
Jayesh Mishra
Jayesh Mishra - avatar
+ 8
A char pointer by default points to the 0th index of the character array. So char* x is pointing to h. Then you increment x by 2 so h+1+1 and that is l. So x is now pointing to l and everything from l is printed.
3rd Nov 2019, 4:30 AM
Avinesh
Avinesh - avatar
+ 2
printf("%c",*x); If you can find the output to this than it would be great.
3rd Nov 2019, 4:40 AM
Avinesh
Avinesh - avatar