GATE | Gate IT 2008 | Question 48

Consider the C program below. What does it print?

filter_none

edit
close

play_arrow

link
brightness_4
code

# include <stdio.h>
# define swapl (a, b) tmp = a; a = b; b = tmp
void swap2 ( int a, int b)
{
        int tmp;
        tmp = a; a = b; b = tmp;
 }
void swap3 (int*a, int*b)
{
        int tmp;
        tmp = *a; *a = *b; *b = tmp;
}
int main ()
{
        int num1 = 5, num2 = 4, tmp;
        if (num1 < num2) {swap1 (num1, num2);}
        if (num1 < num2) {swap2 (num1 + 1, num2);}
        if (num1 >= num2) {swap3 (&num1, &num2);}
        printf ("%d, %d", num1, num2);
}
 /* Add code here. Remove these lines if not writing code */ 

chevron_right


(A) 5, 5
(B) 5, 4
(C) 4, 5
(D) 4, 4


Answer: (C)

Explanation: “if (num1 > = num2) {swap3 (&num1, &num2);}” statement is true, so call by reference will be performed.

Quiz of this Question



My Personal Notes arrow_drop_up

Improved By : GehadAhmed



Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.