Canonical First Program
The following program is written in the C programming language:
#include main()
{
printf("Hello World! \n");
}- C is case sensitive. All commands in C must be lowercase.
- C has a free-form line structure. End of each statement must be marked with a semicolon. Multiple statements can be on the same line. White space is ignored. Statements can continue over many lines.
Canonical First Program Continued
- The C program starting point is identified by the word main().
- This informs the computer as to where the program actually starts. The parentheses that follow the keyword main indicate that there are no arguments supplied to this program (this will be examined later on).
- The two braces, { and }, signify the begin and end segments of the program. In general, braces are used throughout C to enclose a block of statements to be treated as a unit. COMMON ERROR: unbalanced number of open and close curly brackets!
More on the Canonical First Program
- The purpose of the statement
#includeis to allow the use of the printf statement to provide program output. For each function built into the language, an associated header file must be included. Text to be displayed by printf() must be enclosed in double quotes. The program only has the one printf() statement. - printf() is actually a function (procedure) in C that is used for printing variables and text. Where text appears in double quotes "", it is printed without modification. There are some exceptions however. This has to do with the \ and % characters. These characters are modifiers, and for the present the \ followed by the n character represents a newline character.