The structure of a C program is the fixed order of a source file: a documentation comment, preprocessor directives, constant definitions, global declarations, the main() function, then your own functions. The compiler reads the file from top to bottom. You must therefore declare anything before the point where you use it, and that rule gives every program in the C language the same skeleton.
The phrase “C programming structure” has a second meaning: the keyword struct, which groups several variables of different types under one name. This article explains both and shows where people mix them up.
The six sections of a C program
Most C programming tutorials split a program into six parts. Only main() is mandatory, but following the order keeps a file readable and keeps the compiler happy.
1. Documentation
The file opens with a comment that says what the program does, who wrote it and anything a later reader should know. The compiler ignores comments completely. You can write them as /* ... */ blocks, or as // lines since the C99 standard.
2. Link section (preprocessor directives)
Lines that start with # are instructions for the preprocessor, a step that runs before the real compilation. #include <stdio.h> pastes the header file of the standard input/output library into your source. That’s how the compiler learns that printf exists and what arguments it takes. The header holds declarations only, and the linker joins the actual code of printf to your program later.
3. Definition section
#define PI 3.1416 creates a symbolic constant. The preprocessor replaces every PI with the text 3.1416 before the compiler sees the file. Note the missing semicolon: a #define is not a C statement, and the preprocessor would copy a stray ; into every place the name appears.
4. Global declarations
Variables and function prototypes declared outside any function are global. A prototype such as float area(float r); tells the compiler the name, return type and parameters of a function whose body comes further down the file. Keep globals few, because any function can change them and bugs become hard to trace.
5. The main() function
Every hosted C program must have a main() function, and execution starts there. Its body contains a declaration part, where you create local variables, and an executable part made of statements that end with a semicolon. Since C99, reaching the closing brace of main without a return behaves like return 0;, but writing it out is still good practice.
6. Subprograms
User-defined functions come last. Each one does a single, well-defined task, and main() or another function calls it. Splitting work this way is what lets a C program grow to thousands of lines without becoming one unreadable block.

An annotated example: the area of a circle
Here is a short program that uses all six sections. It computes the area of a circle with a radius of 10, using the formula πr².
/* area.c - prints the area of a circle (1) documentation
Author: your name */
#include <stdio.h> /* (2) link section */
#define PI 3.1416 /* (3) definition */
float area(float r); /* (4) global declaration */
int main(void) /* (5) main() */
{
float r = 10; /* declaration part */
int calls = 1;
printf("Area: %.2f\n", area(r)); /* executable part */
printf("Function calls: %d\n", calls);
return 0;
}
float area(float r) /* (6) subprogram */
{
return PI * r * r;
}
Compile it with gcc area.c -o area and it prints Area: 314.16 and then Function calls: 1. Want to see the preprocessor at work? Run gcc -E area.c: the output shows the pasted contents of stdio.h and every PI already replaced by 3.1416.
What %f and %d mean
Inside a printf string, %d and %f are format specifiers. Each one marks where a value goes and says how to read it. %d prints an int as a decimal integer, while %f prints a floating-point number. %.2f limits it to 2 decimal places.
C automatically converts a float passed to printf into a double, so %f works for both. Mixing them up, for example %d with a float, is undefined behavior: the program compiles and prints garbage. The -Wall flag of GCC, the standard compiler on Linux, warns about this mismatch.

Structures in C: the struct keyword
A structure in C is a user-defined data type that groups variables of different data types under a single name. A student record is the classic case: a name is a string, a roll number is an int and marks are a float. An array can’t hold all three because every element of an array has the same type. A struct can.
Definition, declaration and accessing structure members
struct student { /* structure definition */
char name[50];
int roll;
float marks;
};
struct student s1 = { "Reena", 101, 89.5f }; /* structure variable */
struct student *p = &s1; /* structure pointer */
s1.roll = 102; /* dot operator: access through the variable */
p->marks = 91.0f; /* arrow operator: access through a pointer */
The definition only describes a new type and reserves no memory. The compiler allocates memory when you declare a structure variable, either after the closing brace of the definition or later with struct student s1;.
You then reach each structure member with the dot operator. Through a pointer, use the arrow operator: p->marks is shorthand for (*p).marks. Strings inside a struct can’t be assigned with = after initialization, so copy them with strcpy(s1.name, "Arun"); from <string.h>.
Initialization, arrays and typedef
C99 added designated initializers, which set members by name rather than position: struct student s2 = { .roll = 7, .marks = 75.0f };. Members you leave out start at zero.
An array of structures works like any other array, so struct student class[5]; stores five separate records. A structure can also contain another structure (a nested struct). With typedef struct student Student; you can then write Student s1; without repeating the keyword.
Passing structures to functions
A struct passed by value is copied in full, so the function works on a copy and the original stays untouched. Pass a pointer instead when the function must modify the data, or when the struct is large and copying it would waste time. This is why pointers and structures appear together in almost all real C code, from linked lists to the struct stat that Linux system calls fill in for you.

Memory layout: why sizeof is often bigger than you expect
Members are stored in memory in the order you declare them, and the first member sits at the very start of the struct. Between members, though, the compiler may insert padding bytes so that each member lands on an address its type can be read from efficiently. On a typical 64-bit Linux system, struct { char c; int n; char d; } takes 12 bytes, not 6.
Reordering members from largest to smallest usually removes most of the padding. In our view, for most application code it’s a micro-optimization, but in embedded systems, network packets and file formats the exact layout is the whole point.
Print sizeof and offsetof (from <stddef.h>) in a small test program. You’ll see the layout instead of guessing it, and the same habit makes pointers far less mysterious.

The four types of data types in C
Textbooks usually sort C data types into four groups, and the struct belongs to one of them:
- Basic (primary) types:
int,char,floatanddouble, with modifiers such asshort,longandunsigned. - Derived types: arrays, pointers and functions, built from the basic types.
- User-defined types:
struct,union,enumand names created withtypedef. - Void: the absence of a value, used for functions that return nothing and for generic pointers.
What a C structure is not
Several neighboring ideas get confused with the two meanings above.
- A union looks like a struct, but all its members share the same memory. It is at least as large as its largest member, and only one member holds a meaningful value at a time.
- An array groups values of one type, reached by index. A struct groups values of different types, reached by name.
- A class exists in C++ and Java, not in C. A C struct holds data only: no methods, no access control, no constructors.
- A data structure (linked list, stack, tree) is a way of organizing data. In C you usually build one out of structs and pointers, but the two terms are not synonyms.
The program layout described earlier is a different thing again. It’s a convention for ordering a source file, not a type, and the compiler only enforces the part about declaring things before use.
Is C harder than Python, and what to practice next
C asks more of you than Python because you manage memory, types and pointers yourself, and pointers are where many beginners slow down. That effort pays off in systems programming, the focus of linuxfuture.org: the Linux kernel, its system calls and most low-level tools are written in C.
A good next step is to rewrite the circle program so that it reads a radius with scanf("%f", &r). Then store several circles in an array of structs and print each one’s address. For the reference behind every rule above, chapter 6 of The C Programming Language by Kernighan and Ritchie remains the clearest source.
Keep exploring our C and Linux systems programming articles, and compile every snippet yourself as you read.
