I am learning a C++. And in this exercise the output in the console is 01, although the a[1] = 0
#include <iostream>
class A
{
public:
A() { a[0] = 1; a[1] = 0; }
int a[2];
int b(void);
};
int A::b(void)
{
int x = a[0];
a[0] = a[1]; a[1] = x;
return x;
}
int main(void)
{
A a;
a.b();
std::cout << a.b() << a.a[1];
return 0;
}
but if I write the line with cout
in two lines like this:
std::cout << a.b();
std::cout << a[1];
the output is 00.