3i Infotech Placement: Sample Questions 228 - 229 of 1245

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

Question 228

Question

MCQ▾

Output of the following program is

  1. main ()
  2. {
  3.     inti=0;
  4.     for (i=0;i<20;i++)
  5.     {
  6.         switch (i)
  7.         {
  8.             case0:i+=5;
  9.             case1:i+=2;
  10.             case5:i+=5;
  11.             default:i+=4;
  12.             break;
  13.         }
  14.         printf("%d,",i);
  15.     }
  16. }

Choices

Choice (4)

a.

Syntax error

b.

0, 5, 9,13, 17

c.

16,21

d.

5, 9,13, 17

Answer

c.

Explanation

  • In the program
Table Showing the Program
int i = 0;
  • Define the integer variable i = 0
for (i = 0; i < 20; i ++)

{

  • Apply the for loop
switch (i)

{

case 0: i += 5;

case 1: i += 2;

case 5: i += 5;

default: i += 4;

break;

}

  • Using switch case
  • Case 0 = i += 5
    • Here i = 0
    • Case 0 = 0 += 5
    • Case 0 = 5
    • In case 0 i = 5
  • Case 1 = i += 2
    • Here i = 5
    • Case 1 = 5 += 2
    • Case 1 = 7
    • In case 1 i = 7
  • Case 5 = i += 5
    • Here i = 7
    • Case 5 = 7 += 5
    • Case 5 = 12
    • In case 1 i = 12
  • default = i += 4
    • Here i = 12
    • default = 12 += 4
    • default = 16
    • In default i = 16
printf ( “% d,” , i) ;
  • Printf prints the “I” value and i = 16, so, print 16
  • i value was increment in for loop and prints “2” 1
  • So the answer is 16,21

Question 229

Edit

Write in Short

Short Answer▾

What do you mean by the protection fault?

Explanation

  • Protection fault happens when a process accesses the page for which it does not have the access permission.
  • This means that the process is accessing a region in RAM outside its assigned storage area-the operating system typically requires that the task or application be closed.
  • For example, a process incurs the protection fault when it attempts to write a page whose copy on write bit was set during the fork () system call.

Developed by: