Bird
0
0

Which of the following is the correct syntax for an if statement in C?

easy📝 Syntax Q12 of 15
C - onditional Statements
Which of the following is the correct syntax for an if statement in C?
Aif (condition) { printf("Hello"); }
Bif (condition) printf("Hello")
Cif condition: printf("Hello");
Dif condition { printf("Hello"); }
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct if statement syntax in C

    The condition must be inside parentheses, and the code block inside braces.
  2. Step 2: Check each option

    if (condition) { printf("Hello"); } uses parentheses for condition and braces for code block, which is correct syntax.
  3. Final Answer:

    if (condition) { printf("Hello"); } -> Option A
  4. Quick Check:

    Parentheses + braces = correct if syntax [OK]
Quick Trick: Use parentheses for condition and braces for code block [OK]
Common Mistakes:
  • Omitting parentheses around condition
  • Using colon instead of braces
  • Missing semicolon after printf

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes