Open In App

GATE | GATE-CS-2015 (Set 3) | Question 64

Consider the following C program.
The output of the program is __________.




# include <stdio.h>
int f1(void);
int f2(void);
int f3(void);
int x = 10;
int main()
{
    int x = 1;
    x += f1() + f2() + f3() + f2();
    pirntf("%d", x);
    return 0;
}
  
int f1()
{
    int x = 25;
    x++;
    return x;
}
  
int f2( )
{
    static int x = 50;
    x++;
    return x;
}
  
int f3( )
{
    x *= 10;
    return x;
}

(A) 230
(B) 131
(C) 231
(D) 330

Answer: (A)
Explanation:

x += f1() + f2() + f3() + f2();

x = x +  f1() + f2() + f3() + f2();

f1() returns 26

f2() returns 51

f3() returns 100

second call to f2() returns 52 
[Note x is static in f2()]

x = 1 + 26 + 51 + 100 + 52  = 230 

Quiz of this Question

Article Tags :