Lesson not found
Lesson Progress: 0%
Variables are named memory locations that let you store and reuse values in your programs. Think of a variable as a labeled box where you put a number, a letter, or a decimal value. In C, every variable has a type that tells the computer what kind of data the box can hold, such as int for whole numbers, double for decimal numbers, or char for single characters. You give a variable a name and an initial value, and later you can read that value or change it. Variables are essential because they let your program remember information, calculate results, and make decisions based on data. Without variables, every program would be a fixed sequence of steps with no way to adapt or reuse data.
#include <stdio.h>
int main() {
int age;
age = 10;
printf("%d\n", age);
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
int), then a name (like age).int age; declares a variable named age that can hold an integer.age = 10; assigns the value 10 into the variable.age holds 10 until you change it.printf("%d\\n", age); prints the current value stored in age.#include <stdio.h>
int main() {
int score = 95;
printf("%d\n", score);
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
int score = 95;score and put 95inside it right away."95 is called a literal because it is written directly in the code.#include <stdio.h>
int main() {
int a = 5;
int b = 3;
printf("%d\n", a + b);
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
int a = 5; creates one box with 5, and int b = 3; creates another with 3.a + b adds the values stored in both variables.8 is passed directly to printf and printed.#include <stdio.h>
int main() {
int count = 1;
count = 7;
printf("%d\n", count);
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
int count = 1; starts count at 1.count = 7; overwrites the old value with 7.#include <stdio.h>
int main() {
double pi = 3.14;
printf("%.2f\n", pi);
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
double type stores numbers with a decimal point, like 3.14.double pi = 3.14; creates a variable named pi that holds a decimal value.%f prints a double, and %.2f shows exactly two digits after the decimal.double can hold much larger and more precise values than int.double whenever you need fractions, measurements, or any value with a decimal part.#include <stdio.h>
int main() {
char letter = 'Q';
printf("%c\n", letter);
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
char type stores a single character, like a letter or a punctuation mark.char letter = 'Q'; creates a variable and stores the capital letter Q inside it.'Q' or 'z'.%c prints the character stored in a char variable.char is perfect for storing letters, digits as symbols, and punctuation.Test Incomplete