Why do I get ‘command not found’ when trying to run my executable after compilation?

For security reasons, the current directory is not included in your PATH environment variable. You have to prepend ./ to the command to tell the shell explicitly to use the current directory when searching for the command. For example, if your executable is named a.out, you’ll have to type ./a.out to run it.