Thursday, June 28, 2018

Can you initialize multiple variables in one statement?

Yes. You can initialize multiple variables in the same statement. Refer to the previous post and try out the following in Visual Studio Community 2017 (free) :
        int ix = 5, iy = 6;
  cout << ix << "," << iy;
cout << "\n";

This is also possible:

 int iz(7), izz{ 8 };
 cout << iz << "," << izz;
 cout << "\n";

This one as well possible:

 int a = 100, b(50), c{ 100 };
 cout << "a= " << a << " b= " << b << " c= "<< c;
 cout << "\n";

The result of running this is shown here:


Here is a copy of the code.


No comments: