Which of the following correctly declares multiple variables of the same type?
A
int a, b, c; B
int a = 1, b = 2, c = 3; C
int a; b; c; D
Both A and B
Analysis & Theory
Both A and B are correct ways to declare multiple variables. Option C is incorrect because `b` and `c` are undeclared.
What is the output?
```c
int a = 2, b = 3;
printf("%d", a + b);
```
A
2 B
3 C
5 D
6
Analysis & Theory
`a + b = 2 + 3 = 5`
Which of the following is NOT a valid way to assign multiple variables?
A
int x = 5, y = 6; B
int x, y; x = y = 10; C
int x = 5 y = 6; D
int a = 3, b = a + 2;
Analysis & Theory
Option C is missing a comma between `x = 5` and `y = 6`, which is a syntax error.
How do you declare `a`, `b`, and `c` as floats?
A
float a, b, c; B
float a; b; c; C
float (a, b, c); D
float = a, b, c;
Analysis & Theory
`float a, b, c;` correctly declares all three as float variables.
What is the final value of `c`?
```c
int a = 4, b = 5;
int c = a + b;
```
A
9 B
20 C
5 D
4
Analysis & Theory
`a + b = 4 + 5 = 9`
Which is the correct way to declare and initialize `x = 1`, `y = 2`, `z = 3`?
A
int x = 1, y = 2, z = 3; B
int x = 1; int y = 2; int z = 3; C
int x, y, z; x = 1; y = 2; z = 3; D
All of the above
Analysis & Theory
All options are valid for declaring and initializing multiple variables.
What happens here?
```c
int a = 10, b;
b = a;
```
A
Both `a` and `b` are 10 B
`b` becomes 0 C
`a` becomes 0 D
Error
Analysis & Theory
`b = a;` copies the value of `a` (10) into `b`.
Which line of code causes a compile error?
A
int a = 1, b = 2, c = 3; B
int x = 5, y = 6; C
int a, b, = 2; D
int m = 4, n = m + 2;
Analysis & Theory
`int a, b, = 2;` is incorrect syntax — variable name is missing before `=`.
Can you assign one variable’s value to another in declaration?
A
Yes, if the source variable is declared before B
Yes, always C
No, never D
Only with strings
Analysis & Theory
You can use another variable's value during declaration only if it's already declared.
Which of these is the best practice when using many related variables?
A
Use long names B
Use arrays or structures C
Declare in different blocks D
Avoid initializing them
Analysis & Theory
Arrays or structures are better for managing groups of related values.