# Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 201 - 203 of 354

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

## Question 201

C & C Plus Plus
Edit

### Describe in Detail

Essay▾

Write a macro for swapping integers.

### Explanation

1. `#include<iostream.h>`
2. `#include<conio.h>`
3. `#define SWAP(a,b) {int temp; temp=a; a=b; b=temp;}`
4. `void main()`
5. `{`
6. `    clrscr();`
7. `    int x,y;`
8. `    cout≪“Enter two numbers:”;`
9. `    cin≫x≫y;`
10. `    cout≪“x=”≪x≪” y=”≪y;`
11. `    SWAP(x,y);`
12. `    cout≪“nx=”≪x≪” y=”≪y;`
13. `    getch();`
14. `}`

## Question 202

C & C Plus Plus
Edit

### Write in Short

Short Answer▾
1. `main ()`
2. `{`
3. `    clrscr();`
4. `}`
5. `clrscr();`

### Explanation

In a program

 `main ()``{``    clrscr();``}` The first clrscr () occurs inside a function.So, it becomes a function call. clrscr () ; In the second clrscr () ; is a function declaration (because it is not inside any function) .

## Question 203

C & C Plus Plus
Edit

### Describe in Detail

Essay▾
1. `main ()`
2. `{`
3. `    int c[ ] ={ 2.8, 3.4, 4, 6.7, 5};`
4. `    int j,`
5. `    ⚹p =c,`
6. `    ⚹q =c;`
7. `    for (j =0; j<5; j ++ )`
8. `    {`
9. `        printf ( “%d” ⚹c);`
10. `        ++ q;`
11. `    }`
12. `    for (j =0; j<5; j ++ )`
13. `    {`
14. `        printf ( “%d” ⚹p);`
15. `        ++ p;`
16. `    }`
17. `}`

### Explanation

• In a program
• int c [] = {2.8,3.4,4, 6.7,5} in array was integer so can not indicate preceding value
 int c [] = {2.8,3.4,4, 6.7,5} Integer value array int j Integer variable ⚹ p = c,⚹ q = c Pointer C is assigned to both p and q for (j = 0; j < 5; j ++){printf ( “% d” ⚹ c) ;++ q;} In a first loop , q is incremented and not cSo, the value 2 will be printed 5 times for (j = 0; j < 5; j ++){printf ( “% d” ⚹ p) ;++ p;} In a second loop p itself is incrementedSo, the values 23465 will be printed
• So the final answer is 2 2 2 2 2 2 3 4 6 5.

Developed by: