Saturday, 8 August 2026

C 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:

Example

printf("Hello World!");

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:

Example

printf("Hello World!")
error: expected ';' before 'return'

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

printf("Hello World!");
printf("Have a good day!");
return 0;

Example explained

This program contains three statements:

  1. printf("Hello World!");
  2. printf("Have a good day!");
  3. 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.


Challenge: Create a Simple C Program

Test your understanding of C by completing a small coding challenge.

Instructions

Use the editor to complete the following steps:
  1. Write a main() function
  2. Use printf to print Hello, C!
  3. End the program with return 0;

Note: Remember curly braces and semicolons.

ClickCheck Codeto see the result here.

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.

No comments:

Post a Comment