CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Consider the C program below. What does it print?
#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 num 1 = 5, num 2 = 4, tmp;
if (num 1 > num 2)
{ swap 1 (num 1, num 2); }
if (num 1 < num2)
{ swap2 (num1 + 1, num2);}
if (num 1 > = num 2)
{ swap3 (&num1, &num2); }
printf ("%d, %d", num1, num2);
}

A
4, 4
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
5, 5
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
5, 4
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
4, 5
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
Open in App
Solution

The correct option is D 4, 5
Num 1 = 5 num 1 = 4

First condition fail
Second condition fail
Third condition execute because
(num 1> = num2)

So value of a = 4
value of b = 5
i.e., swapping done via call by reference.

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Equations
QUANTITATIVE APTITUDE
Watch in App
Join BYJU'S Learning Program
CrossIcon