In the program below I call a function foo()
which sets a global variable i
and then calls the constructor of class A
, where i
should also be set, but
to 10
. However the output of my program is 3 0
, can you please explain?
#include <iostream>
int i;
class A
{
public:
~A()
{
i=10;
}
};
int foo()
{
i = 3;
A ob;
return i;
}
int main()
{
std::cout << "i = " << foo() << " " << i << "\n";
}