Your First C Program and the Compiler
Why Learn C?
C is one of the most influential programming languages ever created. Operating systems, databases, and even other programming languages are written in C. Learning it teaches you how memory and the machine actually behave.
The Classic First Program
Every C program begins with a main function — the place where execution starts.
#include <stdio.h>
int main(void) {
printf("Hello, DCCPS!\n");
return 0;
}Reading the Code Line by Line
#include <stdio.h>brings in the standard input/output library so we can useprintf.int main(void)defines the main function;intmeans it returns an integer.printfprints text. The\nis a newline character that moves to the next line.return 0;reports success to the operating system.
Compilation: From Source to Program
Unlike Python, C is a compiled language. You cannot run the source code directly. A program called a compiler translates your C file into machine code first.
- Write your code in a file ending in
.c, for examplehello.c. - Compile it:
gcc hello.c -o hello - Run the resulting program:
./hello
The -o hello option names the output program hello. If you skip it, the compiler creates a file called a.out by default.
Statements and Semicolons
In C, almost every statement ends with a semicolon. Forgetting it is the most common beginner error and produces a compile-time message.
A compile-time error stops your program from being built at all. This is actually helpful — the compiler catches many mistakes before the program ever runs.
C is case sensitive. main and Main are different names, and int must be written in lower case.
Discussion
0No comments yet — be the first to leave one!