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.
scoreis anint(whole number),priceis adouble(decimal) andgradeis achar(a single character).score = score + 5;reads the old value, adds 5, and stores the result back in the same box.
#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