Which one of the choices given below would be printed when the following…
GATE · 2006 · IT
Which one of the choices given below would be printed when the following program is executed?
#include
void swap (int *x, int *y)
{
static int *temp;
temp = x;
x = y;
y = temp;
}
void printab ()
{
static int i, a = -3, b = -6;
i = 0;
while (i <= 4)
{
if ((i++)%2 == 1) continue;
a = a + i;
b = b + i;
}
swap (&a, &b);
printf("a = %d, b = %d\\n", a, b);
}
main()
{
printab();
printab();
}
- A.
a = 0, b = 3
a = 0, b = 3 - B.
a = 3, b = 0
a = 12, b = 9 - C.
a = 3, b = 6
a = 3, b = 6 - D.
a = 6, b = 3
a = 15, b = 12
Attempted by 164 students.
Show answer
Correct answer: D
Explore the full course: Iocl Engineers Officers Grade A Paper 2
Loading lesson…