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

C & C Plus Plus
Edit

Describe in Detail

Essay▾
  1. main ()
  2. {
  3.     printf ( “%d” out);
  4. }
  5. intout =100;

Explanation

Compiler error: undefined symbol out in function main.

In a program

Table Showing the Program
  1. main ()
  2. {
  3.     printf ( “%d” out);
  4. }
  5. intout =100;
Print the value of out

The rule is that a variable is available for use from the point of declaration.

Even though is a global variable, it is not available for main.

Hence an error.

Question 349

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. inti =10;
  2. main ()
  3. {
  4.     externinti;
  5.     {
  6.         inti =20;
  7.         {
  8.             constvolatileunsignedi =30;
  9.             printf ( “%d” i);
  10.         }
  11.         printf ( “%d” i);
  12.     }
  13.     printf ( “%d” i);
  14. }

Explanation

30,20, 10

In the program ‘ {’ introduces new block and thus new scope.

Table Shows the Program
int i = 10;Define the global variable integer i = 10
int i = 20;Define integer i = 20
{

const volatile unsigned i = 30;

printf ( “% d” i) ;

}

In the innermost block i is declared as, const volatile unsigned which is valid declaration.

i is assumed of type int.

so, printf prints 30.

printf ( “% d” i) ;

}

In the next block, i has value 20 and so printf prints 20.
printf ( “% d” i) ;

}

In the outermost block, i is declared as extern, so no storage space is allocated for it.

After compilation is over the linker resolves it to global variable i.

Therefore, it prints ‘i’ value as 10.

Developed by: