Hello world!

The following program outputs “Hello world” and exits:

void main() {
    println("Hello world");
}

Like C-based languages, the program starts execution in the main function. In this program we don’t need to return anything from main, so the return type is declared as void. If we wanted to specify an exit status, we could change the return type to int and add a return statement.

To compile and run the code from the command line, we can put the code in a file called for example hello.cx, and then do:

cx hello.cx
./hello # or hello.exe on Windows

Or we can let the C* compiler do both steps using the run command:

cx run hello.cx

If we use the run command, the executable file hello will not be created.

Syntax

The syntax of C* is mostly similar to the C family of languages, but there are some stylistic differences worth noting:

However, to attract attention to more important differences, this documentation uses semicolons and parentheses even if not required.

Comments

C* has two kinds of comments: