C/C++ Arena

Variables change over time

A variable is a named box in memory. Step through and watch each box appear when its line runs, then change when a later line assigns to it.

#include <stdio.h>

int main(void) {
    int score = 10;
    double price = 2.5;
    char grade = 'B';
    score = score + 5;
    price = price * 2;
    grade = 'A';
    printf("%d %.1f %c\n", score, price, grade);
    return 0;
}

Output:

15 5.0 A

From the lesson: Variables and types