0
0
Cprogramming~5 mins

Structure of a C program

Choose your learning style9 modes available
Introduction

A C program needs a clear structure to work correctly. This structure helps the computer understand what to do step by step.

When writing any program in C language.
When you want your program to run without errors.
When you want to organize your code so others can read it easily.
When you want to include libraries or functions in your program.
When you want to start learning programming with C.
Syntax
C
#include <stdio.h>

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

#include <stdio.h> tells the program to use standard input/output functions like printf.

int main() is the starting point of every C program.

Examples
This program prints "Hello, world!" on the screen.
C
#include <stdio.h>

int main() {
    printf("Hello, world!\n");
    return 0;
}
This program shows how to use a variable and print its value.
C
#include <stdio.h>

int main() {
    int number = 5;
    printf("Number is %d\n", number);
    return 0;
}
Sample Program

This simple program prints a welcome message. It shows the basic structure of a C program.

C
#include <stdio.h>

int main() {
    printf("Welcome to C programming!\n");
    return 0;
}
OutputSuccess
Important Notes

Every C program must have a main function; this is where the program starts.

The return 0; line means the program finished successfully.

Comments like // Your code here help explain the code but do not run.

Summary

A C program starts with #include to add libraries.

The main function is the entry point.

Use printf to show messages on the screen.