Menu
Coddy logo textTech

Basic Program Structure

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

Every C program must 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 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.

challenge icon

Challenge

Easy

Create a C program with a main() function. Inside the main() function, write code to output the following text:

This is my first C program!

Cheat sheet

Every C program must start with header directives:

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

All executable code must be inside the main() function:

#include <stdio.h>

int main() {
    printf("This is my first C program!");
    return 0;
}

Every statement ends with a semicolon (;), except for code blocks in curly braces.

Try it yourself

#include <stdio.h>

int main() {
    // Your code here
    
    return 0;
}
quiz iconTest yourself

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

All lessons in Fundamentals