• edited by
18,502 views
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);
}
  1. $5, 5$
  2. $5, 4$
  3. $4, 5$
  4. $4, 4$

7 Answers

Answer:
Position:
Show:

Related questions

12 12 votes
2 answers 2 answers
7.5k
7.5k views
Ishrat Jahan asked Oct 27, 2014
7,497 views
Match the programming paradigms and languages given in the following table. Paradigms Languages(I)Imperative(a)Prolog(II)Object Oriented(b)Lisp(III)Functional(c)C, Fortra...
118 118 votes
10 answers 10 answers
42.4k
42.4k views
Ishrat Jahan asked Oct 31, 2014
42,385 views
Which one of the choices given below would be printed when the following program is executed?#include <stdio.h void swap (int *x, int *y) { static int *temp; temp = x; x ...
65 65 votes
5 answers 5 answers
19.7k
19.7k views
Ishrat Jahan asked Oct 28, 2014
19,735 views
C program is given below:# include <stdio.h int main () { int i, j; char a [3] = {{'a', 'b', 'c'}, {'d', 'e', 'f'}}; char b [3] ; char *p = *b; for (i = 0; i < 2; i++)...
103 103 votes
4 answers 4 answers
25.7k
25.7k views
Ishrat Jahan asked Oct 28, 2014
25,670 views
Consider the C program given below. What does it print?#include <stdio.h int main () { int i, j; int a [8] = {1, 2, 3, 4, 5, 6, 7, 8}; for(i = 0; i < 3; i++) { a[i] = a[i...