LIVE Course for free

Rated by 1 million+ students
Get app now
0 votes
59 views
in Information Technology by (54.3k points)
closed by

Determine the output of the given program.

main()

{

int i = 8;

while (i = 8)

{

printf ("Getting out");

i++;

}

}


1. Getting out is printed infinite times
2. Nothing is printed
3. Getting out is printed once
4. Getting out is printed 7 times

1 Answer

0 votes
by (30.0k points)
selected by
 
Best answer
Correct Answer - Option 1 : Getting out is printed infinite times

Concept:

while loop:

Statements within the while loop would keep getting executed till the condition being tested remains true. When condition becomes false, control passed to the first statement that follows body of the loop. While loop will be executed atleast 0 times.

Syntax:

Initialize loop counter;

While(condition)

{

Statement;

Increment loop counter;

}

Calculation: 

main()

{

int i = 8;

while (i = 8)

{

printf ("Getting out");

i++;

}

}

  • When i = 8, as the condition is satisfied, the print will display Getting out in the output.
  • Now after incrementing i to 9, the while loop gets completed.
  • Again i is assigned 8 and again while loop will be executed.
  • So this process will keep on running infinite times, hence Getting out is printed infinite times.

Hence option(1) is the correct answer.

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...