Multiple choice

What would be the output of the following?

char *fun(char *ptr) { ptr+=3; return(ptr); } void main() { char *x,*y; x="Hello"; y=fun(x); printf("%s",y); }

  1. Hello

  2. lo

  3. llo

  4. Error

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The function fun() increments the pointer by 3 (ptr+=3), advancing it from 'Hello' to point at 'lo'. This pointer is returned to main() where it's printed. String 'Hello' has indices 0-4 for H,e,l,l,o, so +3 points to index 3 which is 'l', making the string 'lo'.