My first Hello World
Let’s start with a simple “Hello World” program. The simplest Hello World you can write in C3 looks like this:
The import
statement imports other modules, and we want printn
which
is in std::io
Next we define a function, which starts with the fn
keyword followed by the return type. In this case we don’t need to return anything, so we use void
. Then follows the name of the function, main
, followed by the parameter list, which is empty.
{
and }
signifies the start and end of the function respectively. Inside we have a single
call to the function printn
in std::io
. We use the last part of the path “io” in front of
the function to identify what module it belongs to.
The io::printn
function takes a single argument and prints it, followed by a line feed After this the function ends and the program terminates.
Compiling the program
Let’s take the above program and put it in a file called hello_world.c3
.
We can then compile it:
And run it:
It should print Hello, World!
and return back to the command line prompt.
If you are on Windows, you will have hello_world.exe
instead. Call it in the same way.
Compiling and running
When we start out it can be useful to compile and then have the compiler start the
program immediately. We can do that with compile-run
:
If you followed along so far: Congratulations! You’re now up and running with C3.