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

if...else Statement in C

The if...else statement is used to execute different blocks of code based on certain conditions. It allows your program to make decisions.

Basic if Statement

Simple if Statement
#include <stdio.h>

int main() {
    int age;
    
    printf("Enter your age: ");
    scanf("%d", &age);
    
    if (age >= 18) {
        printf("You are eligible to vote!\n");
    }
    
    return 0;
}

if...else Statement

if...else Example
#include <stdio.h>

int main() {
    int number;
    
    printf("Enter a number: ");
    scanf("%d", &number);
    
    if (number % 2 == 0) {
        printf("%d is even\n", number);
    } else {
        printf("%d is odd\n", number);
    }
    
    return 0;
}

if...else if...else Statement

Multiple Conditions
#include <stdio.h>

int main() {
    int marks;
    
    printf("Enter your marks: ");
    scanf("%d", &marks);
    
    if (marks >= 90) {
        printf("Grade: A+\n");
    } else if (marks >= 80) {
        printf("Grade: A\n");
    } else if (marks >= 70) {
        printf("Grade: B\n");
    } else if (marks >= 60) {
        printf("Grade: C\n");
    } else {
        printf("Grade: F\n");
    }
    
    return 0;
}

Nested if Statements

Nested if Example
#include <stdio.h>

int main() {
    int age;
    char license;
    
    printf("Enter your age: ");
    scanf("%d", &age);
    
    if (age >= 18) {
        printf("Do you have a driving license? (y/n): ");
        scanf(" %c", &license);
        
        if (license == 'y' || license == 'Y') {
            printf("You can drive!\n");
        } else {
            printf("You need a driving license.\n");
        }
    } else {
        printf("You are too young to drive.\n");
    }
    
    return 0;
}

Explanation

  • if / else: Executes code based on boolean conditions; non-zero is true, zero is false.
  • Chained else if: Useful for mutually exclusive ranges or categories (e.g., grading logic).
  • Nested if: Use judiciously; deep nesting reduces readability—consider early returns or switch.
  • Common pitfalls: Using = instead of ==, forgetting braces, or mismatched conditions.
Keywords
C if else, conditional statements, comparisons, boolean logic, control flow
Quick Tips
  • Use braces even for single statements to avoid errors during future edits.
  • Extract repeated logic into functions to keep condition blocks concise.
  • Prefer switch for many exact-value comparisons on integers or chars.

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.