GATE CS 2024 (Forenoon) — Question 19

Programming in CFunctions, Parameter Passing, Scope Rules, RecursionMCQ1 mark · −1/3 if wrongHard

Consider the following program:
c
1#include <stdio.h>
2void fx( );
3int main( ) {
4    fx( );
5    return 0;
6}
7void fx( ) {
8    char a;
9    if ((a=getchar( )) != '\n')
10        fx( );
11    if (a != '\n')
12        putchar (a);
13}
14
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 terminate with no output
  2. B
    The program will not terminate
  3. C
    The program will terminate with 4321 as output
  4. D
    The program will terminate with 1234 as output
Practise the full 2024-FN paper
Challenge a friend: WhatsApp Telegram
From RENYXERAPractise this subject in the exam simulatorTimed, GATE-style tests with analytics that find your weak topics.
Practise more on Functions, Parameter Passing, Scope Rules, RecursionTimed, in the real exam interface · free to start

A GATE question every morning

One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.

Join
Stuck? Ask in the student group