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

C & C Plus Plus
Edit

Write in Short

Short Answer▾

What is the output of the following program?

  1. inti, j;
  2. for (i =0; i ⇐ 10; i ++ )
  3. {
  4.     j += 5;
  5.     assert(i<5);
  6. }

Explanation

Runtime error: Abnormal problem termination.

assert failed (i < 5) , < file name > , < line number >

In a program

Table Shows the Program
int i, j;Define integer variable I and j.
for (i = 0; i ⇐ 10; i ++)

{

j += 5;

assert (i < 5) ;

}

  • Asserts are used during runtime debugging to make sure that certain conditions are satisfied.
  • If assertion fails during runtime, the program will terminate reporting the same.
  • This assertion will fail when i becomes 5.
  • After debugging use #undef NDEBUGand this will disable all the assertions from the source code.

Question 93

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. main ()
  2. {
  3.     inta[ ] ={ 10, 20, 30, 40, 50}, j, ⚹p;
  4.     for (j =0; j<5; j ++ )
  5.     {
  6.         printf (%d, ⚹a);
  7.         a ++;
  8.     }
  9.     p =a;
  10.     for (j =0; j<5; j ++ )
  11.     {
  12.         printf (%d, ⚹p);
  13.         p ++;
  14.     }
  15. }

Explanation

Compiler error: Lvalue required.

In a program

Table Shows the Program
int a [] = {10, 20, 30,40, 50} , j, ⚹ p;Define the integer array a [] , j variable and also int pointer p.
for (j = 0; j < 5; j ++)

{

printf (% d, ⚹ a) ;

a ++ ;

}

Applies the for loop

Error is in line with statement a ++ .

The operand must be an Lvalue and may be of any of scalar type for the any operator- array name only when subscribed is an Lvalue.

(An lvalue is an object that persists beyond a single expression- an object that has a name. Lvalue includes all variables, including non modifiable (const) variables)

Simply array name is a non-modifiable Lvalue

Define the Lvalue of Expression

Developed by: