Learn the basic anatomy of a C program, including headers, the main function, and statements.
Every C program, regardless of its complexity, follows a fundamental structure that is crucial to understand from the very beginning. This structure provides a standardized framework that the compiler uses to interpret and execute your code. A typical C program consists of several key sections. First, you have the Preprocessor Directives. These are lines that begin with a `#` symbol, with `#include` being the most common. The `#include <stdio.h>` directive, for example, tells the compiler to include the contents of the 'standard input-output' header file before compilation. This file contains declarations for essential functions like `printf()`. Next is the `main` function, written as `int main()`. The `main` function is the heart of every C program; it is the entry point where the program's execution begins. The `int` before `main` specifies that this function will return an integer value to the operating system upon completion. The parentheses `()` after `main` indicate that it is a function. The entire body of the `main` function, and indeed any function, is enclosed in curly braces `{}`. Inside these braces, you write your program's logic, which consists of statements and expressions. Each statement in C is a command that performs an action and must end with a semicolon `;`. This semicolon acts as a terminator, signaling the end of one instruction. For example, `printf("Hello, World!\n");` is a statement that calls the `printf` function. Finally, the `return 0;` statement is typically the last line in the `main` function. It signifies that the program has executed successfully and returns a status code of 0 to the operating system.