🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: C Control Flow: all 10 questions

Quiz: C Control Flow · Question 9 of 10

What does this print? (code)

What does this print?

#include <stdio.h>
int main(void) {
    int stars = 0;
    for (int i = 1; i <= 4; i++)
        for (int j = 1; j <= i; j++)
            stars++;
    printf("%d\n", stars);
    return 0;
}
  1. A.4
  2. B.16
  3. C.10
  4. D.8
Answer & explanation

Correct answer: 10

The inner loop runs i times: 1 + 2 + 3 + 4 = 10, the number of stars in a 4-row triangle.

Can you get the rest right without peeking?

Take the timed Quiz: C Control Flow quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →