How to initialize multiple variables in C++ to the same value?

Viewed 34809

Would this kind of variable assignment work?

double a = 2.0,
x, y, z = 0.5;

Would the second line of code work properly and initialize x, y, z each to 0.5?

7 Answers

You could do that in a single line like this:

double x = 0.5, y = 0.5, z = 0.5;
Related