There seems to be a difference between how c++ increments a global vs local int variable. Can anybody explain why the following code behaves the way it does?
#include<iostream>
using namespace std;
int global = 0;
int main() {
  int local = 0;
  global = (++global) + (++global);
  local =  (++local)  + (++local);
  cout<<global<<endl; // 3
  cout<<local<<endl; // 4
  return 0;
}
Here's my g++ version used if that matters:
gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2)