Menu
CoddyTech

Basic Program Structure

Part of the Fundamentals section of Coddy's C journey. Lesson 4 of 63.

Most C programs start with header directives like:

 #include <stdio.h> // Header for input/output
 #include <math.h> // Header for math functions

These directives include header files containing declarations for functions and objects your program uses.

All executable code must be inside a function. Execution starts in the main() function, which is the entry point of the program. For example:

#include <stdio.h> // Header for input/output

int main() { // Main function
    printf("This is my first C program!"); // Output statement
    return 0; // Return statement - not mandatory in modern C 
}

Remember, every statement ends with a semicolon (;), except for code blocks in curly braces. The semicolon is mandatory and tells C that you've reached the end of a statement.

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals

Practice on your own: Online C compiler