C

The foundation of modern programming

C Overview

C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, with a static type system. By design, C provides constructs that map efficiently to typical machine instructions.

Paradigm

Procedural, imperative, structured

Designed by

Dennis Ritchie

First appeared

1972

Stable release

C18 (June 2018)

Key Features

Common Use Cases

System Programming

Operating systems, device drivers, firmware.

Embedded Systems

Microcontrollers, IoT devices, automotive systems.

High-Performance Computing

Scientific computing, game engines, real-time systems.

Language Development

Used to implement other programming languages.

Example Code

/* Basic C program demonstrating core concepts */
#include <stdio.h>
#include <stdlib.h>

// Function prototype
int factorial(int n);

// Structure example
struct Point {
    int x;
    int y;
};

int main() {
    // Variables and pointers
    int number = 5;
    int *ptr = &number;
    
    printf("Value: %d, Address: %p\n", number, (void*)ptr);
    
    // Function call
    printf("Factorial of %d is %d\n", number, factorial(number));
    
    // Structure usage
    struct Point p1 = {10, 20};
    printf("Point coordinates: (%d, %d)\n", p1.x, p1.y);
    
    // Dynamic memory allocation
    int *arr = (int*)malloc(5 * sizeof(int));
    if (arr == NULL) {
        fprintf(stderr, "Memory allocation failed\n");
        return 1;
    }
    
    for (int i = 0; i < 5; i++) {
        arr[i] = i * i;
    }
    
    free(arr); // Don't forget to free memory
    
    return 0;
}

// Function definition
int factorial(int n) {
    if (n == 0) return 1;
    return n * factorial(n - 1);
}

Learning Resources