C Statements
Statements
A computer program is a list of instructions that a computer follows.
In C, these instructions are called statements.
The following statement tells the program to print the text Hello World! to the screen:
Every statement in C must end with a semicolon ;.
If you forget the semicolon, the compiler will show an error and the program will not run:
Many Statements
Most C programs contain more than one statement.
Statements are executed one by one, in the same order as they are written:
Example explained
This program contains three statements:
printf("Hello World!");printf("Have a good day!");return 0;
The first statement runs first and prints Hello World!.
Then the second statement runs and prints Have a good day!.
Finally, the last statement runs and ends the program.
Remember: Each statement is one instruction, and it must end with a semicolon.
Coming up: The next chapter will show you how to control output and add new lines.