Don't quite understand the output of the following C++ program.
#include <iostream>
#include <sys/types.h>
void foo(int *p) {
std::cout << p << std::endl;
(*p) ++;
}
int main() {
int i = 100;
if (fork() == 0) {
foo(&i);
std::cout << i << std::endl;
} else {
foo(&i);
std::cout << i << std::endl;
}
}
A sample output may be
0x10f273070
101
0x10f273070
101
Why the addresses are the same and output are both 101? I would expect one process outputs 101, the other outputs 102.