C Statements: Understanding Instructions in Programming
C statements are the building blocks of a computer program, consisting of a sequence of instructions that the compiler executes. Each statement directs the computer to perform a specific action. For instance, a simple statement like printf("Hello World");
instructs the compiler to display the text "Hello World" on the screen.
C Statements
A computer program consists of a list of "instructions" for the computer to execute. In programming, these instructions are called statements.
The following statement "instructs" the compiler to print "Hello World" to the screen:
Example
printf("Hello World!");
It's important to end each statement with a semicolon ;
. Forgetting it will result in an error:
Example
printf("Hello World!")
error: expected ';' before 'return'
Many Statements:
Most C programs have multiple statements that are executed one by one in the order they appear:
Example
printf("Hello World!");
printf("Have a good day!");
return 0;
Example explained:
1. printf("Hello World!");
prints "Hello World!" to the screen.
2. printf("Have a good day!");
prints "Have a good day!" to the screen.
3. return 0;
ends the C program successfully.
Remember to always end statements with a semicolon to avoid errors.
Next: You'll learn how to control output and insert new lines for better readability.