Consider the following C code segment. int a, b, c = 0; void prtFun(void);…

GATE · 2012 · CS · Computer Science & IT

Consider the following C code segment.

int a, b, c = 0;
void prtFun(void);
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;

  1. A.

    314142\begin{array}{ll} \text{3} & \text{1} \\ \text{4} & \text{1} \\ \text{4} & \text{2} \\ \end{array}

  2. B.

    426161\begin{array}{ll} \text{4} & \text{2} \\ \text{6} & \text{1} \\ \text{6} & \text{1} \\ \end{array}

  3. C.

    426220\begin{array}{ll} \text{4} & \text{2} \\ \text{6} & \text{2} \\ \text{2} & \text{0} \\ \end{array}

  4. D.

    424220\begin{array}{ll} \text{4} & \text{2} \\ \text{4} & \text{2} \\ \text{2} & \text{0} \\ \end{array}

Attempted by 257 students.

Sign up free to check your answer

Sign up free

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…