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

Input and Output in C

Input and output operations are essential for interactive programs. C provides several functions for reading input from users and displaying output.

Output Functions

printf() Function

Used to display formatted output to the screen.

printf() Examples
#include <stdio.h>

int main() {
    int age = 25;
    float height = 5.9;
    char grade = 'A';
    
    printf("Hello, World!\n");
    printf("Age: %d\n", age);
    printf("Height: %.1f feet\n", height);
    printf("Grade: %c\n", grade);
    printf("Multiple values: %d, %.2f, %c\n", age, height, grade);
    
    return 0;
}

Input Functions

scanf() Function

Used to read formatted input from the user.

scanf() Examples
#include <stdio.h>

int main() {
    int age;
    float salary;
    char grade;
    
    printf("Enter your age: ");
    scanf("%d", &age);
    
    printf("Enter your salary: ");
    scanf("%f", &salary);
    
    printf("Enter your grade: ");
    scanf(" %c", &grade);  // Note the space before %c
    
    printf("\nYou entered:\n");
    printf("Age: %d\n", age);
    printf("Salary: %.2f\n", salary);
    printf("Grade: %c\n", grade);
    
    return 0;
}

Format Specifiers

SpecifierData TypeExample
%dintprintf("%d", 42);
%ffloatprintf("%.2f", 3.14);
%ccharprintf("%c", 'A');
%sstringprintf("%s", "Hello");
%lfdoublescanf("%lf", &num);
Important

Always use the address operator (&) with scanf() for variables, except for strings.

Explanation

  • printf: Prints formatted output using format specifiers like %d, %f, %s.
  • scanf: Reads user input; pass variable addresses (e.g., &age) except for strings, which are arrays.
  • Format specifiers: Must match the variable type to avoid undefined behavior or crashes.
  • Whitespace: When reading char, use a leading space in " %c" to eat leftover newlines.
Keywords
C input output, printf, scanf, format specifiers, address-of
Quick Tips
  • Validate scanf return value to ensure inputs were read successfully.
  • Use fgets for safer string input and parse with sscanf.
  • Prefer explicit widths (e.g., %.2f) to format numeric output neatly.

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.