C

C Tutorial — Learn C Programming

Key takeaway: This free C tutorial teaches you systems programming from scratch — variables, pointers, arrays, functions, structs, and memory management — with practical code examples you can compile and run.

C is a general-purpose, procedural programming language created in 1972. It is used for operating systems, embedded systems, game engines, and performance-critical applications. This tutorial is for beginners, CS students, and developers who want to understand how computers work at a low level.

Last updated: September 2026

Pointer Arithmetic in C

Pointer arithmetic allows you to perform mathematical operations on pointers. This is particularly useful when working with arrays and dynamic memory allocation.

Basic Pointer Arithmetic Operations

Increment and Decrement
#include <stdio.h>

int main() {
    int arr[5] = {10, 20, 30, 40, 50};
    int *ptr = arr;
    
    printf("Original pointer address: %p\n", ptr);
    printf("Value at pointer: %d\n", *ptr);
    
    // Increment pointer
    ptr++;
    printf("After increment: %p\n", ptr);
    printf("Value at pointer: %d\n", *ptr);
    
    // Increment by 2
    ptr += 2;
    printf("After adding 2: %p\n", ptr);
    printf("Value at pointer: %d\n", *ptr);
    
    // Decrement pointer
    ptr--;
    printf("After decrement: %p\n", ptr);
    printf("Value at pointer: %d\n", *ptr);
    
    return 0;
}

Pointer Subtraction

Distance Between Pointers
#include <stdio.h>

int main() {
    int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int *start = &arr[2];  // Points to arr[2]
    int *end = &arr[7];    // Points to arr[7]
    
    printf("Start pointer points to: %d\n", *start);
    printf("End pointer points to: %d\n", *end);
    
    // Calculate distance
    int distance = end - start;
    printf("Distance between pointers: %d elements\n", distance);
    
    // Verify by accessing elements
    printf("Elements between start and end: ");
    for (int *p = start; p <= end; p++) {
        printf("%d ", *p);
    }
    printf("\n");
    
    return 0;
}

Pointer Comparison

Comparing Pointers
#include <stdio.h>

int main() {
    int arr[5] = {10, 20, 30, 40, 50};
    int *ptr1 = &arr[1];
    int *ptr2 = &arr[3];
    int *ptr3 = &arr[1];
    
    printf("ptr1 points to: %d\n", *ptr1);
    printf("ptr2 points to: %d\n", *ptr2);
    printf("ptr3 points to: %d\n", *ptr3);
    
    // Pointer comparisons
    if (ptr1 == ptr3) {
        printf("ptr1 and ptr3 point to the same location\n");
    }
    
    if (ptr1 < ptr2) {
        printf("ptr1 comes before ptr2 in memory\n");
    }
    
    if (ptr2 > ptr1) {
        printf("ptr2 comes after ptr1 in memory\n");
    }
    
    return 0;
}

Practical Example: Array Traversal

Efficient Array Processing
#include <stdio.h>

int findElement(int *arr, int size, int target) {
    int *end = arr + size;  // Pointer to end of array
    
    for (int *ptr = arr; ptr < end; ptr++) {
        if (*ptr == target) {
            return ptr - arr;  // Return index
        }
    }
    return -1;  // Not found
}

void reverseArray(int *arr, int size) {
    int *start = arr;
    int *end = arr + size - 1;
    
    while (start < end) {
        // Swap elements
        int temp = *start;
        *start = *end;
        *end = temp;
        
        start++;
        end--;
    }
}

int main() {
    int numbers[] = {10, 25, 30, 45, 50};
    int size = 5;
    
    printf("Original array: ");
    for (int i = 0; i < size; i++) {
        printf("%d ", numbers[i]);
    }
    printf("\n");
    
    // Find element
    int index = findElement(numbers, size, 30);
    if (index != -1) {
        printf("Element 30 found at index: %d\n", index);
    }
    
    // Reverse array
    reverseArray(numbers, size);
    printf("Reversed array: ");
    for (int i = 0; i < size; i++) {
        printf("%d ", numbers[i]);
    }
    printf("\n");
    
    return 0;
}
Key Points:
  • Pointer arithmetic is scaled by the size of the data type
  • Adding 1 to an int pointer moves it by sizeof(int) bytes
  • Pointer subtraction gives the number of elements between pointers
  • Only pointers to the same array should be compared or subtracted

Frequently Asked Questions

C is a foundational systems programming language that's been around since the 1970s. It's the base for Linux, Windows, and most operating systems. Learning C gives you deep understanding of memory, pointers, and how computers work — skills that transfer to every other language. According to the TIOBE Index, C consistently ranks in the top 2 most popular languages.

No, zero experience needed. Our C programming tutorial is designed for complete beginners. We start with Hello World and gradually progress to pointers and memory management. Basic computer literacy and logical thinking are helpful but not required.

Just a C compiler — or use our free online compiler. For beginners, our online C compiler requires no installation. For local development, use GCC (available on all platforms). IDEs like VS Code, Code::Blocks, or Dev-C++ also work well.

2–4 weeks for basics, 3–6 months for proficiency. With 1–2 hours daily practice, you can learn syntax, loops, and functions in a few weeks. Mastering pointers, memory management, and data structures takes 6–12 months. Practice with our C programming examples.

C programming skills open doors to various career paths including system programming, embedded systems development, operating system development, device driver programming, game development, and firmware development. Many companies in automotive, aerospace, telecommunications, and IoT sectors actively seek C programmers.

Yes, extremely relevant. C consistently ranks in the top 2 on TIOBE and powers Linux, embedded systems, IoT, automotive software, and game engines. Understanding C makes you a better programmer in any language since most runtimes (Python, Java, Node.js) are themselves written in C.