Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 214 - 215 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 214

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. voidmain ()
  2. {
  3.     inti =10, j =2;
  4.     int ⚹ip =&i, ⚹jp =&j;
  5.     intk =⚹ ip/⚹jp;
  6.     printf (“%d”, k);
  7. }

Explanation

Compiler Error: “Unexpected end of file in comment started in line 5”

In the program

Table Shows the Program
int i = 10, j = 2;
  • Given the integer variable i = 10 and j = 2
int ⚹ ip = &i, ⚹ jp = &j;
  • Pointer ip stores the address of I and pointer jp stores the address of j.
int k =⚹ ip/ ⚹ jp;
  • The programmer intended to divide two integers, but by the “maximum munch” rule, the compiler treats the operator sequence/and ⚹ as / ⚹ which happens to be the starting of comment.
  • To force what is intended by the programmer, int k =⚹ ip/ ⚹ jp; // give space explicitly separating/and ⚹ //orint k =⚹ ip/ (⚹ jp) ; // put braces to force the intention

Question 215

C & C Plus Plus
Edit

Describe in Detail

Essay▾
  1. #defineclrscr () 100
  2. main ()
  3. {
  4.     clrscr ();
  5.     printf ( “%d” clrscr () );
  6. }

Explanation

  • In a program preprocessor executes as a separate pass before the execution of the compiler.
Table Shows the Program
#define clrscr () 100Given the clrscr () value is 100.
main ()

{

clrscr () ;

printf ( “% d” clrscr () ) ;

}

So, textual replacement of clrscr () to 100 occurs.

The input program to compiler look like this:

Main ()

{

100;

Printf ( “% d” , 100) ;

}

  • So, the answer is 100
  • NOTE (100; is an executable statement but with no action. So doesn՚t give any problem.)

Developed by: