Hello, World!
Read · 1 of 5
A program is a list of instructions
The computer follows them one at a time, top to bottom. This is the smallest useful C program: it prints one line.
1#include <stdio.h>23int main() {4 printf("Hello, World!\n");5 return 0;6}
Read this lesson as text
The smallest C program, line by line.
A program is a list of instructions
The computer follows them one at a time, top to bottom. This is the smallest useful C program: it prints one line.
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}What happens when you run it
- Your code: hello.c: text you can read
- Compiler: gcc checks it and translates it
- Program: machine instructions
- Output: what you see printed
Watch it run
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}- Line 1: #include <stdio.h> brings in the standard input/output tools, like printf. Almost every C program starts with it.
- Line 3: Every C program starts running inside main(). The code between { and } is what runs.
- Line 4: printf prints the text inside the quotes. \n is a special pair of characters meaning "new line".
- Line 5: return 0 tells the operating system the program finished without problems.
Your turn to guess
#include <stdio.h>
int main() {
printf("Hi\n");
printf("there\n");
return 0;
}What does this print?
- Hi there
- Hi there
- Hithere
Show the answer
Hi there Each \n ends the line, so "there" starts on a new one.
Exercise: Say hello
Print exactly: Hello, ICEM!