C Introduction
C is a programming language for writing fast programs that sit close to the machine. A program is a list of instructions, and a computer follows them one by one.
A first program
The program prints one line and stops. That line proves the print worked, and every program in this course starts from this shape.
#include <stdio.h>
int main() {
printf("Hello, world!\n");
return 0;
}Two prints in order
The two prints run in order, top to bottom. Hello comes first, then Goodbye.
#include <stdio.h>
int main() {
printf("Hello\n");
printf("Goodbye\n");
return 0;
}Example
#include <stdio.h>
int main() {
printf("C is small and fast.\n");
printf("C sits close to the machine.\n");
printf("C has been used for 50 years.\n");
return 0;
}Key points
- C is over 50 years old, and operating systems, embedded devices, and game engines are still written in it.
- C code lives as plain text in a file.
- A compiler turns C code into a program a computer can run.
- The line #include <stdio.h> brings in the tools for printing.
- Running starts at int main().
- Curly braces hold the statements inside main.
- printf prints text to the screen.
- The two characters \n start a new line.
- A semicolon marks the end of each statement.
- return 0; at the end means the program ended well.
Three lines print in order. All three sentences appear, which proves each print ran.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
Which tool turns C code into a program a computer can run?