Bird
0
0

You want to declare and initialize three variables a, b, and c with values 1, 2, and 3 respectively in one line. Which is the correct C statement?

hard📝 Application Q15 of 15
C - Variables and Data Types
You want to declare and initialize three variables a, b, and c with values 1, 2, and 3 respectively in one line. Which is the correct C statement?
Aint a, b, c = 1, 2, 3;
Bint a = 1, b = 2, c = 3;
Cint a = 1; int b = 2; int c = 3;
Dint a = 1; b = 2; c = 3;
Step-by-Step Solution
Solution:
  1. Step 1: Understand multiple declarations with initialization

    In C, you can declare multiple variables of the same type in one line by separating them with commas, and initialize each with =.
  2. Step 2: Analyze each option

    int a = 1, b = 2, c = 3; correctly declares and initializes all three variables in one statement. int a, b, c = 1, 2, 3; is invalid syntax. int a = 1; int b = 2; int c = 3; uses multiple statements, not one line. int a = 1; b = 2; c = 3; is invalid because b and c are not declared.
  3. Final Answer:

    int a = 1, b = 2, c = 3; -> Option B
  4. Quick Check:

    Use commas to declare and initialize multiple variables in one line [OK]
Quick Trick: Use commas to declare and initialize multiple variables [OK]
Common Mistakes:
  • Trying to assign multiple values without commas
  • Forgetting to declare all variables
  • Using multiple statements instead of one line

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes