Question Details

Consider the following program, what is the output printed ?


Options

A

10

B

56

C

15

D

25

Show Answer
Correct Answer
A 10

Solution :

The correct option is 10.

Analysis of the Code in the Image:
The provided image contains the following C program:
void f(int i, int j) { if (i < j) { i = 0; while (i < 10) { j = j + 2; i++; } printf(i); } }
int main() { int i = 9, int j = 10; f(i, j); return 0; }

Let's trace the execution of this program step-by-step:

1. Initialization in main():
The execution begins in the main() function where the variables i and j are initialized:
i = 9
j = 10
The function f(i, j) is then called with these values, passing 9 for the parameter i and 10 for the parameter j.

2. Conditional Check in f():
Inside f(int i, int j), the first statement is an if condition:
i<j
Substituting the arguments:
9<10
Since 9 is less than 10, this condition evaluates to true, and execution enters the if block.

3. Executing the Loop:
Upon entering the if block, the variable i is re-assigned to 0:
i = 0
Next, the program encounters a while loop:
i<10
During each iteration of this loop, j is incremented by 2 and i is incremented by 1 (i++). The loop runs for i = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

4. Termination and Printing:
After the 10th iteration, i is incremented to 10. The loop condition is checked again:
10<10
Since this condition is false, the loop terminates. The statement immediately following the loop is:
printf(i);
Since the value of i at this point is 10, the program prints 10 as the final output.

Transparent Access on Mindyard

Built for Learners & Educators Alike

Completely free for students. Educators & coaching institutes get 2 months free Pro trial to create tests.

FREE FOR STUDENTS

Practice & Learn Free for Students

Access unlimited practice questions, detailed step-by-step solutions, and exam study materials — completely free for students.

  • Unlimited mock tests & question bank practice
  • Full access to curated study library & formula notes
  • 100% free for students • No credit card required
2 MONTHS FREE TRIAL

Educators & Coaching Institutes

Create and conduct professional online assessments with AI question generation, tab proctoring, and comprehensive batch management.

  • AI question uploader & rapid test generator
  • Anti-cheating tab proctoring & performance reports
  • Full Pro access free for 60 days • No upfront commitment
Discover more resources

You may also like

Mock Tests

View All
  • GATE
  • beginner
  • 3 hours
  • civil engineering

Prepare for GATE 2026 Civil Engineering with the latest question papers, previous year papers, detailed solutions, syllabus, exam pattern, preparation tips, mock tests, and subject-wise study material. Download GATE 2026 CE question papers with solutions in PDF format and boost your preparation for top engineering institutes and PSU recruitment.

  • GATE
  • beginner
  • 3 hours
  • electronics and communication engineering

Prepare effectively for GATE 2026 Electronics & Communication Engineering (EC) with this comprehensive Question Paper with Solutions. This resource includes detailed explanations, concept-wise solutions, previous year paper analysis, and exam-oriented practice to help aspirants strengthen core subjects like Electronic Devices, Analog Circuits, Digital Circuits, Signals & Systems, Network Theory, Control Systems, Electromagnetics, Communications, and more. Perfect for revision, self-assessment, and boosting your GATE 2026 EC preparation strategy.

Ask AI Tutor
5 left
Q1 View Question & Options
AI Tutor is solving this question...
Reading question context & options...
Ask your own doubt or choose a quick prompt: