Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

GATE | GATE-CS-2015 (Set 1) | Question 21

  • Last Updated : 28 Jun, 2021

The output of the following C program is __________.

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

void f1 (int a, int b)
  int c;
  c=a; a=b; b=c;
void f2 (int *a, int *b)
  int c;
  c=*a; *a=*b;*b=c;
int main()
  int a=4, b=5, c=6;
  f1(a, b);
  f2(&b, &c);
  printf (ā€œ%dā€, c-a-b);
  return 0;

(A) -5
(B) -4
(C) 5
(D) 3

Answer: (A)

Explanation: The function call to to f1(a, b) won’t have any effect as the values are passed by value.

The function call f2(&b, &c) swaps values of b and c. So b becomes 6 and c becomes 5. Value of c-a-b becomes 5-4-6 which is -5.

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :