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

Variables and Constants in C

Variables are storage locations with an associated name that can contain data. Constants are fixed values that cannot be changed during program execution.

Variables

A variable is a name given to a memory location where data is stored. Variables must be declared before use.

Variable Declaration and Initialization
#include <stdio.h>

int main() {
    // Variable declaration
    int age;
    float salary;
    char grade;
    
    // Variable initialization
    age = 25;
    salary = 50000.50;
    grade = 'A';
    
    // Declaration and initialization together
    int count = 10;
    double pi = 3.14159;
    
    printf("Age: %d\n", age);
    printf("Salary: %.2f\n", salary);
    printf("Grade: %c\n", grade);
    
    return 0;
}

Variable Naming Rules

Good Practice
  • Use descriptive names: studentAge instead of a
  • Use camelCase: firstName
  • Use underscores: first_name
Avoid
  • Single letter names (except for loops)
  • Starting with numbers: 2name
  • Using keywords: int, float

Constants

Constants are fixed values that cannot be modified during program execution. There are several ways to define constants in C:

Different Types of Constants
#include <stdio.h>
#define PI 3.14159  // Preprocessor constant

int main() {
    // const keyword
    const int MAX_SIZE = 100;
    const float GRAVITY = 9.8;
    
    // Literal constants
    int number = 42;        // Integer literal
    float price = 19.99;    // Float literal
    char letter = 'X';      // Character literal
    char name[] = "John";   // String literal
    
    printf("PI: %.5f\n", PI);
    printf("Max Size: %d\n", MAX_SIZE);
    printf("Gravity: %.1f\n", GRAVITY);
    
    return 0;
}
Tip

Use #define for compile-time constants and const for runtime constants. Constants are typically written in UPPERCASE.

Explanation

  • Variables: Named memory locations with a specific type; declare before use and initialize to avoid undefined values.
  • Constants: Values that do not change; use const for typed, scoped constants and #define for macros.
  • Why it matters: Clear variable names and appropriate constants make code safer and easier to maintain.
  • Common pitfalls: Modifying a const value, mixing #define macros with typed constants, or using vague names.
Keywords
C variables, constants, const, #define, initialization, naming
Quick Tips
  • Prefer const for type safety and scope; reserve #define for simple symbolic values.
  • Use UPPERCASE names for macros (e.g., MAX_SIZE) to distinguish from variables.
  • Initialize variables at declaration when possible to avoid undefined behavior.

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.