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

C & C Plus Plus
Edit

Describe in Detail

Essay▾
  1. voidmain ()
  2. {
  3.     inti;
  4.     for (i =1; i<=4, i ++ )
  5.     switch (i)
  6.     {
  7.         case1:printf ( “%d”, i);
  8.         break;
  9.         case2:printf ( “%d”, i);
  10.         break;
  11.         case3:printf ( “%d” ,i);
  12.         break;
  13.         case4:printf ( “%d”, i);
  14.         break;
  15.     }
  16. }

Explanation

  • In the program
Table Showing the Program
int i;
  • Define the integer variable i
for (i = 1; i <= 4, i ++)
  • Check the for loop
switch (i)

{

case 1: printf ( “% d” , i) ;

break;

  • In the for loop i = 1 than check case 1 and printf prints the value of i = 1
case 2: printf ( “% d” , i) ;

break;

  • In the for loop i = 2 than check case 2 and printf prints the value of i = 2
case 3: printf ( “% d” , i) ;

break;

  • In the for loop i = 3 than check case 3 and printf prints the value of i = 3
case 4: printf ( “% d” , i) ;

break;

  • In the for loop i = 1 than check case 4 and printf prints the value of i = 4

Question 65

C & C Plus Plus
Edit

Describe in Detail

Essay▾
  1. main ()
  2. {
  3.     inti;
  4.     printf ( “%d” scanf( “%d” &i) );//value 10 is given as input here
  5. }

Explanation

  • In a program
    Table Showning the Program
    int i;Define integer variable i
    printf ( “% d” scanf ( “% d” &i) ) ; //value 10 is given as input hereHere scanf returns number of items successfully read and not 10.

    Here 10 is given as input.

    This should have been scanned successfully.

    So, number of items read is 1.

  • So. The answer is 1.

Developed by: