• Home
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • TypeScript
    • Introduction to TypeScript
    • TypeScript Developer
  • React.js
    • Introduction to React
    • React Developer
  • Python
    • Introduction to Python
    • Python Developer
  • C++
    • Introduction to C++
    • C++ Developer
  • C Language
    • Introduction to C
    • C Developer
  • Rust
    • Introduction to Rust
    • Rust Developer
  • Zig
    • Introduction to Zig
    • Zig Developer
  • Linux Shell
    • Introduction to the Linux Shell
    • Linux Shell Developer
  • Interactive Training
  • Pricing
  • Brainstorm
STEMTrainingGrounds
  • Courses
    • Home
    • JavaScript
      • Introduction to JavaScript
      • JavaScript Developer
    • TypeScript
      • Introduction to TypeScript
      • TypeScript Developer
    • React
      • Introduction to React
      • React Developer
    • Python
      • Introduction to Python
      • Python Developer
    • C++
      • Introduction to C++
      • C++ Developer
    • C Language
      • Introduction to C
      • C Developer
    • Rust
      • Introduction to Rust
      • Rust Developer
    • Zig
      • Introduction to Zig
      • Zig Developer
    • Linux Shell
      • Introduction to the Linux Shell
      • Linux Shell Developer
  • Interactive Training
  • Pricing
  • Reading Grounds

Quick Links

  • About Us
  • Pricing
  • Partnership
  • Brainstorm
  • Terms
  • Privacy
  • Refunds
  • Featured on DanielLaunches

Courses

  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • TypeScript
    • Introduction to TypeScript
    • TypeScript Developer
  • React
    • Introduction to React
    • React Developer
  • Python
    • Introduction to Python
    • Python Developer
  • C++
    • Introduction to C++
    • C++ Developer
  • C Language
    • Introduction to C
    • C Developer
  • Rust
    • Introduction to Rust
    • Rust Developer
  • Zig
    • Introduction to Zig
    • Zig Developer
  • Linux Shell
    • Introduction to the Linux Shell
    • Linux Shell Developer

Newsletter

Subscribe to our free monthly newsletter, for a quick update on Python, JavaScript, and React news

© 2025 - 2026 STEMTrainingGrounds. All Rights Reserved.

C Developer - Lesson 2

Lesson not found

Variables

Lesson Progress: 0%

Lesson Progress: 0%
Variables
Lesson Incomplete
Lesson not found

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.

Code Example
#include <stdio.h>

int main() {
    int age;
    age = 10;
    printf("%d\n", age);
    return 0;
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

C Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • To create a variable, first write its type (like int), then a name (like age).
  • The line int age; declares a variable named age that can hold an integer.
  • The next line age = 10; assigns the value 10 into the variable.
  • After assignment, age holds 10 until you change it.
  • printf("%d\\n", age); prints the current value stored in age.
Code Example
#include <stdio.h>

int main() {
    int score = 95;
    printf("%d\n", score);
    return 0;
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

C Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • You can declare and initialize a variable in one step: int score = 95;
  • This tells the computer: "make an integer box named score and put 95inside it right away."
  • Initializing in one step is shorter and clearer than declaring and assigning separately.
  • The value 95 is called a literal because it is written directly in the code.
  • Once the variable holds a value, you can print it, use it in math, or change it later.
Code Example
#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.

C Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • You can create multiple variables and use them together in expressions.
  • int a = 5; creates one box with 5, and int b = 3; creates another with 3.
  • The expression a + b adds the values stored in both variables.
  • The result 8 is passed directly to printf and printed.
  • Using variables lets you compute new values without changing the original data stored in them.
Code Example
#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.

C Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • A variable’s value can be changed after it is created.
  • int count = 1; starts count at 1.
  • Then count = 7; overwrites the old value with 7.
  • When you assign a new value, the old value is lost and cannot be recovered.
  • This ability to change values is what makes variables "variable" — they can hold different values at different times.
Code Example
#include <stdio.h>

int main() {
    double pi = 3.14;
    printf("%.2f\n", pi);
    return 0;
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

C Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • The 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.
  • The format specifier %f prints a double, and %.2f shows exactly two digits after the decimal.
  • double can hold much larger and more precise values than int.
  • Use double whenever you need fractions, measurements, or any value with a decimal part.
Code Example
#include <stdio.h>

int main() {
    char letter = 'Q';
    printf("%c\n", letter);
    return 0;
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

C Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • The 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.
  • Character values are written inside single quotes, like 'Q' or 'z'.
  • The format specifier %c prints the character stored in a char variable.
  • char is perfect for storing letters, digits as symbols, and punctuation.

Test Incomplete

What is a variable in C?

Question #

1/15

Score

0/0 - 0.0 %