Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
434 views
in Information Technology by (114k points)
closed by

Determine the output of the given program.

#include <stdio.h>

int main()

{

int i, a[4] = {3, 1, 2, 4}, result;

result = a[0];

for(i = 1; i < 4; i++)

{

if(result > a[i])

continue;

result = a[i];

}

printf("%d", result);

return 0;


1. 1
2. 4
3. 3
4. Error

1 Answer

0 votes
by (115k points)
selected by
 
Best answer
Correct Answer - Option 2 : 4

Concept:

1.The continue statement in C programming works somewhat like the break statement. Instead of forcing termination, it forces the next iteration of the loop to take place, skipping any code in between.

2. For the for loop, the continue statement causes the conditional test and increment portions of the loop to execute. For the while and do...while loops, continue statement causes the program control to pass to the conditional tests.

3.The continue statement skips the current iteration of the loop and continues with the next iteration.

Its syntax is:

continue;

Program Output:

#include <stdio.h>

int main()

{

int i, a[4] = {3, 1, 2, 4}, result;

result = a[0];

for(i = 1; i < 4; i++)

{

if(result > a[i])

continue;

result = a[i];

}

printf("%d", result);

return 0;

Code Explanation:

  • Here first result = 3. 
  • for loop will run from 1st to 3rd position of array a.
  • When result = 3, the condition if(result > a[i]) is satisfied for i = 1 and 2, but due to the continue statement it will skip this iteration and i will be updated to the 3rd position of array a.
  • Now for i = 3, if(result > a[i])  condition is not satisfied and result is assigned 4.
  • At last, the print will be executed and we will get the output as 4. Hence option (2) 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

...