GATE Assistant

Past questions › Computer Science and Information Technology › GATE 2024 set1

GATE 2024 set1 · CS · MCQ · 1 mark · Programming and Data Structures › Recursion

GATE 2024 set1 Computer Science and Information Technology question: Consider the following C program: code code Assume that the input to the program from…

Consider the following C program:

#include <stdio.h>
void fX();
int main(){
    fX();
    return 0;}
void fX(){
  char a;
  if((a=getchar()) != '\n')
      fX();
  if(a != '\n')
      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

Show answer

Official answer: C

Practise this question with exam-style marking

Discussion

No discussion yet.

Join the discussion