GATE CS 2024, set 1 · Question 19 · Programming and Data Structures · Multiple choice (MCQ) · 1 mark · −1/3 for a wrong answer

Consider the following C program:
#include <stdio.h> void fX(); int main() fX(); return 0; void fX() char a; if((a=getchar()) != ' ') fX(); if(a != ' ') putchar(a);
Assume that the input to the program from the command line is 1234 followed by a newline character. Which one of the following statements is CORRECT ?

  1. (A) The program will not terminate
  2. (B) The program will terminate with no output
  3. (C) The program will terminate with 4321 as output
  4. (D) The program will terminate with 1234 as output
Answer

Answer (C)

Answer from the official GATE CS 2024 answer key.

The step-by-step solution, where available, is part of GATE CS Pro. See what Pro includes