Bird
0
0

Which of the following is the correct syntax to return the value 5 inside a for loop in C?

easy📝 Syntax Q12 of 15
C - Loop Control Statements
Which of the following is the correct syntax to return the value 5 inside a for loop in C?
Afor(int i=0; i<3; i++) { return 5; }
Bfor(int i=0; i<3; i++) return(5)
Cfor(int i=0; i<3; i++) { return; 5; }
Dfor(int i=0; i<3; i++) { return 5 }
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of return statement

    Return must be followed by a value and a semicolon inside braces if used.
  2. Step 2: Analyze each option

    for(int i=0; i<3; i++) { return 5; } uses correct syntax with braces and semicolon. for(int i=0; i<3; i++) return(5) misses semicolon, invalid. for(int i=0; i<3; i++) { return; 5; } has return without value then 5; which is invalid. for(int i=0; i<3; i++) { return 5 } misses semicolon after return 5.
  3. Final Answer:

    for(int i=0; i<3; i++) { return 5; } -> Option A
  4. Quick Check:

    Return syntax needs value and semicolon [OK]
Quick Trick: Return must have value and semicolon inside braces [OK]
Common Mistakes:
  • Omitting semicolon after return
  • Placing code after return on same line
  • Using return without value in non-void function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes