38.0k views
4 votes
How would you consolidate the following declaration statements into one statement?

int x = 7;

int y = 16;

int z = 28;

A.
int x = 7; y = 16; z = 28;

B.
int x = 7 y = 16 z = 28;

C.
int x, y, z = 7, 16, 28

D.
int x = 7, y = 16, z = 28;

User Kendal
by
7.7k points

1 Answer

0 votes

Answer:

Correct option is (D) that is int x = 7, y = 16, z = 28;.

Step-by-step explanation:

To initialize multiple variables in a single statement, we use this syntax "data type variable=value, variable=value, variable=value;". here data type should be same for all the variable. All the variables are separated by ",". In this way we can initialize many variables in a single statement,but all the variables must have same data type.In option A,";" is used to separate the variables but this is used to end a statement.In option B, nothing used to separate all the variables and in option C, there is no ";" to end the statement.

User Gul Ershad
by
7.8k points

No related questions found