#include <iostream>
int c=0;
int fun()
{
for(int i=1;i<=100;i++)
c++;
return c;
}
int main()
{
std::cout<<fun()<<' '<<c;
std::cout << " " << c;
}
100 0 100
c is changed. cout buffered the 0 before it changed. One of our experts on undefined behavior can comment, I am not great at that stuff. But its generally not good to modify something and print it in the same statement.
My understanding is that the output of the original program should be "100 100" since C++17. Before that I'm not sure if it's undefined behaviour or if the order is just unspecified. The rules are so complicated in this area that I wouldn't recommend writing code that relies on it.