ccompiler.inOnline C Compiler & Docs
C Tutorial2026-03-152 min read

Master C programming fundamentals including syntax, data types, variables, arithmetic operators, and control flow with runnable code examples.

Introduction to C Programming

Created by Dennis Ritchie at Bell Labs in 1972, C is an efficient, procedural, statically typed programming language that powers operating system kernels (Linux, macOS, Windows), embedded devices, real-time engines, and database systems worldwide.

Understanding C gives you direct insight into how computers manage memory, CPU registers, and hardware resources.

Anatomy of a C Program

Every standard C program starts execution from the main() function:

c (ISO Standard)
#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}

Breakdown of the Code:

  • #include <stdio.h>: Preprocessor directive that imports standard input/output functions, such as printf().
  • int main(): The entry point function required in every executable C application.
  • printf(...): Formats and outputs characters to the standard console.
  • return 0;: Returns exit status code 0 to the operating system, signaling successful termination.

Fundamental Data Types in C

Data TypeKeywordTypical SizeValue Range / Specifier
Integerint4 bytes-2,147,483,648 to 2,147,483,647 (%d)
Characterchar1 byteSingle ASCII character (%c)
Single Precision Floatfloat4 bytes6–7 decimal digits (%f)
Double Precision Floatdouble8 bytes15–17 decimal digits (%lf)
c (ISO Standard)
#include <stdio.h>

int main() {
    int age = 21;
    char initial = 'M';
    float temperature = 98.6f;
    double preciseValue = 3.141592653589793;

    printf("Age: %d\n", age);
    printf("Initial: %c\n", initial);
    printf("Temperature: %.1f\n", temperature);
    printf("Pi: %.6lf\n", preciseValue);

    return 0;
}

Control Flow: Conditionals and Loops

1. Conditional Logic (if-else)

c (ISO Standard)
#include <stdio.h>

int main() {
    int number = 17;

    if (number % 2 == 0) {
        printf("%d is even.\n", number);
    } else {
        printf("%d is odd.\n", number);
    }

    return 0;
}

2. For Loops & While Loops

c (ISO Standard)
#include <stdio.h>

int main() {
    printf("Counting 1 to 5 with a for loop:\n");
    for (int i = 1; i <= 5; i++) {
        printf("%d ", i);
    }
    printf("\n");

    return 0;
}

Next Steps in Your C Journey

Related Tutorials & Examples