Bird
0
0

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

easy📝 Syntax Q3 of 15
C - onditional Statements
Which of the following shows the correct syntax for an if statement in C?
Aif x > 0 then printf("Positive");
Bif x > 0 { printf("Positive"); }
Cif (x > 0) { printf("Positive"); }
Dif (x > 0) printf "Positive";
Step-by-Step Solution
Solution:
  1. Step 1: Recall C syntax for if

    The condition must be inside parentheses.
  2. Step 2: Check braces and semicolons

    Braces are used to group statements; semicolons end statements.
  3. Final Answer:

    if (x > 0) { printf("Positive"); } -> Option C
  4. Quick Check:

    Condition in parentheses, braces for block [OK]
Quick Trick: Use parentheses for conditions in if [OK]
Common Mistakes:
  • Omitting parentheses around condition
  • Using 'then' keyword (not in C)
  • Missing braces or semicolons

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes