C Hello World: Write, Compile and Run Your First Program
C Hello World: Write, Compile and Run Your First Program
A school office wants a program that prints a welcome message. Before reading marks or making decisions, we need to connect a saved source file with a running program.
A C program describes operations in source code. A compiler translates that source into an executable; running the executable performs the operations. In a hosted program, main is the starting function.
Explain
Explain the roles of the source file, compiler and running program.
Trace
Replace the school name with Hill School while preserving the newline.
Apply
Distinguish saving a source file from building and running it.
Hello World: follow the data
Start
A school office wants a program that prints a welcome message. Before reading marks or making decisions, we need to connect a saved source file with a running program.
Operation
A C program describes operations in source code. A compiler translates that source into an executable; running the executable performs the operations. In a hosted program, main is the starting function.
Result
Welcome to River School
Understand the operation
Save the code as school.c. The stdio.h header declares printf, the standard output function. int main(void) says that the starting function returns an int and receives no parameters. Braces enclose its body; the semicolon ends a statement.
The text inside double quotes is a string literal. The escape sequence \n requests a newline; it is not two printed characters. return 0 reports successful termination to the environment. These statements do not run merely because a file was saved.
Read the complete C program
This complete C17 program uses a small school example. Read declarations before the statements that use their values. Each printf format describes how the corresponding value is written to standard output.
C17 · complete program
#include <stdio.h>
int main(void) {
printf("Welcome to River School\n");
return 0;
}
Expected output
Welcome to River School
Run in C compiler →Follow the values through the code
C17 · code used in this explanation
#include <stdio.h>
int main(void) {
printf("Welcome to River School\n");
return 0;
}
The compiler checks the source and links the required library support into a runnable program.
When you run it, main calls printf and then returns zero. The text goes to standard output, usually your terminal.
Follow the worked calculation
Read the starting values
The compiler checks the source and links the required library support into a runnable program.
Perform the operation
When you run it, main calls printf and then returns zero. The text goes to standard output, usually your terminal.
Check the observable result
Welcome to River School
Welcome to River School
Compile the saved file, then run the executable
For a local GCC or Clang toolchain, use the terminal commands below from the source file’s folder. -std=c17 selects the language version; warning flags help expose questionable code. Install a compiler appropriate to your operating system first.
Unix-like shell commands:
cc -std=c17 -Wall -Wextra -Wpedantic school.c -o school
./schoolThe compiler command finishes before you run ./school. On Windows, use the executable name and command syntax provided by your installed toolchain. A missing compiler is a setup problem, while a missing semicolon is a source error.
Try a small variation
C17 · code used in this explanation
#include <stdio.h>
int main(void) {
printf("Welcome to River School\n");
return 0;
}
Replace the school name with Hill School while preserving the newline.
Worked answer
Only the string content changes. The function call, parentheses, semicolon and newline remain, so the output is one line with the new school name.
C17 · complete program
#include <stdio.h>
int main(void) {
printf("Welcome to Hill School\n");
return 0;
}
Expected output
Welcome to Hill School
Run in C compiler →Recognize the important boundaries
C is case-sensitive: Main is not the standard starting name main. Most expression statements need a semicolon, but a function definition’s closing brace does not require one.
Use the C online compiler or a local C compiler. Do not use void main as a portable replacement for int main(void).
Check your understanding
Choose the answer, then compare the reasoning for every option.
Use the idea independently
A C program describes operations in source code. A compiler translates that source into an executable; running the executable performs the operations. In a hosted program, main is the starting function.
Continue with compiler messages and local setup.
Continue with a second greeting program.
Language reference: WG14 C11 committee draft. These examples use the C17-compatible subset of the explained language features.
Reaching the recap and completing the quizzes are separate milestones.