Consider the following C program: void abc(char *s) { if (s[0] == '\0')…

PYQ GATE 2001Modified — slightly modified from the official paper; see the solution

Consider the following C program:

void abc(char *s)
{
  if (s[0] == '\0') return;
  abc(s + 1);
  abc(s + 1);
  printf("%c", s[0]);
}
int main(void)
{
  abc("123");
  return 0;
}

(a) What will be the output of the program?

(b) If abc(s) is called with a null-terminated string s of length n characters (not counting the null (‘\0’) character), how many characters will be printed by abc(s)?

Sign up free to check your answer

Sign up free

Explore the full course: Zero To Hero

Loading lesson…