Back
Close

Hello World in C++, the long way

Matthew-S
33.2K views

How programs run

For compiled languages like C and C++, source code like program.c is fed into the compiler which outputs an executable simply called program (or program.exe if on Windows). This program can be run from the command line with ./program. The leading ./ essentially expands to your current directory which under Linux would probably turn into something like /home/name/Documents/my-project/program. After running this, every program returns an exit code. Normally, this is used to indicate whether the program crashed (with anything other than 0 meaning a failure). However, for testing purposed, we can return whatever we would like. To view the exit code, immediately after running a command, type this command. Linux: echo $? Windows: echo %errorlevel%. For instance, try changing directories with cd .. and view the exit code. Now try cd nonexistentDir and you will see a difference.

Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io