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

Structures in C

Structures allow you to group related data of different types under a single name. They are user-defined data types that help organize complex data.

Structure Declaration and Definition

Basic Structure
#include <stdio.h>
#include <string.h>

// Structure declaration
struct Student {
    int id;
    char name[50];
    float gpa;
    int age;
};

int main() {
    // Structure variable declaration
    struct Student student1;
    
    // Assigning values
    student1.id = 101;
    strcpy(student1.name, "Alice Johnson");
    student1.gpa = 3.85;
    student1.age = 20;
    
    // Displaying values
    printf("Student Information:\n");
    printf("ID: %d\n", student1.id);
    printf("Name: %s\n", student1.name);
    printf("GPA: %.2f\n", student1.gpa);
    printf("Age: %d\n", student1.age);
    
    return 0;
}

Structure Initialization

Different Initialization Methods
#include <stdio.h>

struct Point {
    int x;
    int y;
};

int main() {
    // Method 1: Initialize during declaration
    struct Point p1 = {10, 20};
    
    // Method 2: Designated initializers
    struct Point p2 = {.x = 5, .y = 15};
    
    // Method 3: Partial initialization
    struct Point p3 = {30};  // y will be 0
    
    printf("Point 1: (%d, %d)\n", p1.x, p1.y);
    printf("Point 2: (%d, %d)\n", p2.x, p2.y);
    printf("Point 3: (%d, %d)\n", p3.x, p3.y);
    
    return 0;
}

Array of Structures

Managing Multiple Records
#include <stdio.h>
#include <string.h>

struct Employee {
    int id;
    char name[30];
    float salary;
};

int main() {
    struct Employee employees[3] = {
        {1, "John Doe", 50000.0},
        {2, "Jane Smith", 55000.0},
        {3, "Bob Wilson", 48000.0}
    };
    
    printf("Employee Records:\n");
    printf("%-5s %-15s %-10s\n", "ID", "Name", "Salary");
    printf("--------------------------------\n");
    
    for (int i = 0; i < 3; i++) {
        printf("%-5d %-15s $%.2f\n", 
               employees[i].id, 
               employees[i].name, 
               employees[i].salary);
    }
    
    return 0;
}

Nested Structures

Structure within Structure
#include <stdio.h>
#include <string.h>

struct Address {
    char street[50];
    char city[30];
    int zipCode;
};

struct Person {
    char name[50];
    int age;
    struct Address address;  // Nested structure
};

int main() {
    struct Person person;
    
    strcpy(person.name, "Alice Cooper");
    person.age = 28;
    strcpy(person.address.street, "123 Main St");
    strcpy(person.address.city, "New York");
    person.address.zipCode = 10001;
    
    printf("Person Information:\n");
    printf("Name: %s\n", person.name);
    printf("Age: %d\n", person.age);
    printf("Address: %s, %s %d\n", 
           person.address.street,
           person.address.city,
           person.address.zipCode);
    
    return 0;
}
Key Points:
  • Use . (dot operator) to access structure members
  • Structures can contain arrays, pointers, and other structures
  • Memory is allocated for all members together
  • Structure assignment copies all members

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.