Remember main has 'argv[0]' containing entire pathname of executable
Not necessarily. For example, if you put the source you supplied into a file "./test.cpp", then type the command:
It will make the executable 'test' in the current dir (wherever that is, and assuming it's writable).
Now run the executable just made:
Fragment of output:
That is, the executable receives the relative path to itself, without any information about where the current working directory is. Yes, the working dir path can be obtained (man getcwd).
Other relative paths have similar problems, such as ones containing "../".
The whole thing is a bit more of a puzzle than it first seems. Some (or most) of this is mentioned in the answers of the StackExchange thread I linked.