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. #defineSWAP(a,b) {inttemp; temp=a; a=b; b=temp;}
  4. voidmain()
  5. {
  6.     clrscr();
  7.     intx,y;
  8.     cout≪“Entertwonumbers:”;
  9.     cinxy;
  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

Table Shows the Program
  1. main ()
  2. {
  3.     clrscr();
  4. }
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.     intc[ ] ={ 2.8, 3.4, 4, 6.7, 5};
  4.     intj,
  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
Table Shows the Program
int c [] = {2.8,3.4,4, 6.7,5}Integer value array
int jInteger 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 c

So, 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 incremented

So, the values 23465 will be printed

  • So the final answer is 2 2 2 2 2 2 3 4 6 5.

Developed by: