Prev Index Next

Introduction

Programs, Statements, and I/O

A "Hello World" program in C* looks like this:

function main() => int {
	<< "Hello World" << "\n";
}

A program consists of a set of definitions, mostly function definitions, and must contain a "main" function returning an int. Functions consist of statements, which are terminated with a semicolon, like in C++. Extra whitespace is ignored. Etc.

Input and output for standard in and standard out ("the keyboard" and "the screen") doesn't require an explicit stream, and doesn't require any libraries to be included. As shown above, an output statement begins with the << operator. Input begins with >>. Multiple expressions can still be strung together, as shown above.

Variable declarations

Variables are defined the same as in C++: a type followed by a list of variables.

int x := 0, y;

x receives an initial value of 0, while y contains a garbage value. (It is an error to use an uninitialized value, and a compiler should find as many of these errors as it can.)

Note the new assignment operator. The plain "=" operator is no longer present in the language, and has been replaced with ":=". This prevents programmers from writing "=" when they mean "==".

Arrays and pointers are declared differently than in C++, as explained later in the array and pointer sections. The qualifiers const and static are retained, as in C++; however, only local variables can be static, which causes them to retain their values for successive calls of the function. (In C++, variables declared static outside a function have file scope - that meaning of static is removed from C*.)

References have different syntax in C*. They require the qualifier "ref" rather than the "&" syntax:

ref int x := y;  //x is an alias for y

Declarations in Input

Variable declarations can appear directly in input statements. This:

>> int x >> int y;

is shorthand for:

int x, y;
>> x >> y;

Prev Index Next