# Languages-C & C Plus Plus [Redpine Infotech Placement]: Sample Questions 5 - 5 of 5

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

## Question 5

C & C Plus Plus

### Question

MCQ▾What is output for the following program?

`#include<stdio.h>`

`#define swap (a, b)`

`temp=a,`

`a=b,`

`b=temp;`

`main()`

`{`

`int a=5, b=6;`

`int temp;`

`if(a>b)`

`swap (a,b);`

`printf(“a=%d, b=%d” a, b);`

`}`

### 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

#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. |