Redpine Infotech Placement: Sample Questions 19 - 19 of 19

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 19

Question

MCQ▾

What is output for the following program?

  1. #include<stdio.h>
  2. #defineswap (a, b)
  3. temp=a,
  4. a=b,
  5. b=temp;
  6. main()
  7. {
  8.     inta=5, b=6;
  9.     inttemp;
  10.     if(a>b)
  11.     swap (a,b);
  12.     printf(“a=%d, b=%d” a, b);
  13. }

Choices

Choice (4)

a.

a = 0 b = 6

b.

a = 6 b = 5

c.

a = 5 b = 6

d.

Question does not provide sufficient data or is vague

Answer

c.

Explanation

Table Shows the Program
#include < tdio. h >Standard library function
#define swap (a, b)

temp = a, a = b, b = temp;

It is a function to swap two numbers, but it done as pre-processor define not as normal function.
main ()startup after initialization
int a = 5, b = 6;

int temp;

declare integer a = 5 and b = 6 and temp
if (a > b) ;

swap (a, b)

If (a > b) is false condition, so swap function is not entered.
printf ( “a =% d, b =% d” a, b) ;So, print a = 5 and b = 6, because ‘a’ contains 5 and ‘b’ contains 6.

Developed by: