For Loops: viva questions and MCQs
Computer Programming Lab (C), Unit 5. 100+ For Loops questions with explanations (Computer Programming Lab (C)). Topics: C For Output, C For. Take a free test now.
Topics
- C For Output: line shows, printf, loop tests, program reports, tests divisors, prints, product, execute
- C For: pattern program, header executed, nested loops, expression, controls, update, visible, inside
Key terms: line shows, printf, loop tests, program reports, tests divisors, prints, pattern program, header executed, nested loops, expression, controls, update
Sample questions with answers
for (int i = 1; i <= 10; i++) printf("%d x %d = %d\n", 12, i, 12*i); The 4th line shows the product:
Options: A) 36 B) 48 C) 16 D) 60
Answer: B) 48. Multiplication table.
In C for loops, "Loop variable scope" means:
Options: A) A lone semicolon that acts as a loop body B) for (int i …) keeps i visible only inside the loop in C99 C) Loop that controls columns in a pattern program D) Loop that runs a known number of times
Answer: B) for (int i …) keeps i visible only inside the loop in C99. Loop variable scope: for (int i …) keeps i visible only inside the loop in C99.
How many times does for (i = 5; i < 12; i++) execute its body?
Options: A) 8 B) 6 C) 12 D) 7
Answer: D) 7. Runs for i = a … b−1.