0

Using Android Marshmallow CppDroid app, which uses C++98 but supports some C++11.

I'm following a C++ course, and I'm confused by the output of the following:

int a=0, b=0, c=0;
std::cout << "a:" << a << '\n' << "b:" << b << '\n' << "c:" << c << '\n';
// output is 
// a:0
// b:0
// c:0
a = b++, c++
std::cout << "a:" << a << '\n' << "b:" << b << '\n' << "c:" << c << '\n';
// Output is 
// a:0
// b:1
// c:1

I'm confused as to why the assignment operator did not assign the value of c++ to a.

EDIT

As noted by the comment by @molbdnilo, this is not a matter of precedence, but rather a matter of the values equaling 0 because of the increment operator c++ used instead of ++c.

int a=0, b=0, c=0;
cout<<"a:"<<a<<'\n'<<"b:"<<b<<'\n'<<"c:"<<c<<"\n\n";
// output is 
// a:0
// b:0
// c:0
a = ++b,++c;
cout<<"a:"<<a<<'\n'<<"b:"<<b<<'\n'<<"c:"<<c<<"\n\n";
// output is 
// a:1
// b:1
// c:1
scriptkiddie
  • 159
  • 3
  • 13

0 Answers0