All categories
    CBeginner

    C Basics

    Learn C fundamentals: printf output, variables, data types, arithmetic operators, and constants for absolute beginners.

    01Hello, World

    main.c
    #include <stdio.h>
    
    int main() {
        printf("Hello, World!\n");
        return 0;
    }
    Output
    Hello, World!

    02Variables and types

    main.c
    #include <stdio.h>
    
    int main() {
        int age = 36;
        double height = 1.68;
        char grade = 'A';
        printf("%d %.2f %c\n", age, height, grade);
        return 0;
    }
    Output
    36 1.68 A

    03Arithmetic operators

    main.c
    #include <stdio.h>
    
    int main() {
        int a = 10, b = 3;
        printf("%d\n", a + b);
        printf("%d\n", a - b);
        printf("%d\n", a * b);
        printf("%d\n", a / b);
        printf("%d\n", a % b);
        return 0;
    }
    Output
    13
    7
    30
    3
    1

    04Constants with #define

    main.c
    #include <stdio.h>
    #define PI 3.14159
    
    int main() {
        double r = 2.0;
        printf("Area = %.2f\n", PI * r * r);
        return 0;
    }
    Output
    Area = 12.57