Languages [3i Infotech Placement]: Sample Questions 321 - 322 of 546

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

Question 321

Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. voidmain ()
  2. {
  3.     while (1)
  4.     {
  5.         if (printf ( “%d” printf ( “%d” ) ) )
  6.         break;
  7.         else
  8.         continue;
  9.     }
  10. }

Explanation

In the program

Table Shows the Program
while (1)

{

if (printf ( “% d” printf ( “% d” ) ) )

break;

else

continue;

}

The inner printf executes first to print some garbage values.

The printf returns no of characters printed and this value also cannot be predicted.

Still the outer printf prints something and so returns a non-zero value.

So, it encounters the break statement and comes out of the while statements.

Question 322

Edit

Describe in Detail

Essay▾
  1. #include<studio.h>
  2. main ()
  3. {
  4.     inti =1, j =2;
  5.     switch (i)
  6.     {
  7.         case1:Printf ( “GOOD” );
  8.         break;
  9.         casej:Printf ( “BAD” );
  10.         break;
  11.     }
  12. }

Explanation

  • In a program
Table Shows the Program
int i = 1, j = 2;Define the integer variables i and j
  1. switch (i)
  2. {
  3.     case1:Printf ( “GOOD” );
  4.     break;
  5.     casej:Printf ( “BAD” );
  6.     break;
  7. }
Given the switch case

Here the case statement can have only constant expressions

(this implies that we cannot use variable names directly so an error)

  • So the answer is Compiler error: Constant expression required in function main.
  • NOTE: Enumerated types can be used in case statements.

Developed by: