Skip to content
Related Articles

Related Articles

GATE | GATE-IT-2004 | Question 60

View Discussion
Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 28 Jun, 2021
View Discussion
Improve Article
Save Article

What is the output of the following program?




#include <stdio.h>
int funcf (int x);
int funcg (int y);
  
main()
{
    int x = 5, y = 10, count;
    for (count = 1; count <= 2; ++count)
    {
        y += funcf(x) + funcg(x);
        printf ("%d ", y);
    }
}
  
funcf(int x)
{
    int y;
    y = funcg(x);
    return (y);
}
  
funcg(int x)
{
    static int y = 10;
    y += 1;
    return (y+x);
}


(A) 43 80
(B) 42 74
(C) 33 37
(D) 32 32


Answer: (A)

Explanation: The count=1 and it goes till two,so following statement will be executed twice.

 y += funcf(x) + funcg(x); 

1st call- funcg(x);   // y = 11        y+x=  16.

2nd call funcg(x); // y= 12         y+x=  17.

First iteration-> main()->y = 16+17 +10 = 43

Second iteration-> main() y= 18+19 +43 =80

So the Answer is A

See more about static variables at: https://www.geeksforgeeks.org/g-fact-80/

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!