Gate CS-2012 Question Paper With Solutions

Q. 49 Consider the following C code segment.

int a, b, c = 0;
void prtFun (void);
int main ()
{
    static int a = 1; /* line 1 */
    prtFun();
    a += 1;
    prtFun();
    printf ( "\n %d %d " , a, b) ;
}
  
void prtFun (void)
{
    static int a = 2; /* line 2 */
    int b = 1;
    a += ++b;
    printf (" \n %d %d " , a, b);
}

What output will be generated by the given code segment if:
Line 1 is replaced by auto int a = 1;
Line 2 is replaced by register int a = 2;

(A)

3 1
4 1
4 2

(B)

 4 2
6 1
6 1
4 2
6 2
2 0

(D)

4 2
4 2
2 0

Answer: (D)

Explanation:

Gate CS-2012 Question Paper With Solutions

Learn More:   Gate EC-2014 - 1 Question Paper With Solutions

LEAVE A REPLY

Please enter your comment!
Please enter your name here