33 33 votes Consider the C program below. What does it print?# include <stdio.h> # define swap1 (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); } $5, 5$$5, 4$$4, 5$$4, 4$ Programming in C gateit-2008 programming programming-in-c easy parameter-passing + – Ishrat Jahan 18.5k views answer comment Share Follow Print See all 3 Comments 3 3 Comments reply Prashant_Dubey commented Aug 7, 2024 reply Follow flag if (num1 > num2) {swap1 (num1, num2);} if (num1 < num2) {swap2 (num1 + 1, num2);} if (num1 > = num2) {swap3 (&num1, &num2);} Now ans will be option (b) , First if condition is True so macros will be expanded and it will swap the value of num1 and num2 so num1 becomes 4 and num2 becomes 5 , 2nd if condition is False now come to 3 rd if condition which is true and it's a real swap of num values using the call by reference, num1 becomes 5 and num 2 become 4. 2 2 replyShare Prashant_Dubey commented Aug 7, 2024 reply Follow flag K&R Pg.no. 89 3 3 replyShare spongebob commented Nov 12, 2025 reply Follow flag I think the question was edited multiple times as different asnwers over time are using different code (especially the if conditions).This code is the one I found in gfg too as of the time I'm writing this.Right answer is this accepted answer, where only statement 3 is getting executed. if (num1 < num2) {swap1 (num1, num2);} if (num1 < num2) {swap2 (num1 + 1, num2);} if (num1 > = num2) {swap3 (&num1, &num2);} 0 0 replyShare Please log in or register to add a comment.
0 0 votes EXTRA(optional): https://onlinegdb.com/3h9SZeBoZ Sudo_404_Div answered Jul 18 • edited Jul 20 by Sudo_404_Div Sudo_404_Div comment Share Follow 0 reply Please log in or register to add a comment.