ProgrammingHardProduct company OA

What is printed?

What is printed?
char s[] = "xya", *p = s;
char a = *p++;
char b = *++p;
char c = ++*p;
printf("%c%c%c %s", a, b, c, s);
  1. A. xaa xyb
  2. B. xab xyb
  3. C. xyb xyb
  4. D. xab xya

Correct answer: B. xab xyb

*p++ reads 'x' and moves p to s[1]. *++p moves p to s[2] first and reads 'a'. ++*p increments the character at s[2], making it 'b', and yields 'b'. So the string itself is now "xyb".

More C Programming questions

Exams that ask this topic