Nearby lessons

11 of 72

C - Variables

Variables is one of the foundational topics in C programming. This lesson explains What is a Variable?, Variables and Naming Rules and Program: declare, assign, change, print with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.

What is a Variable?

A variable is a named memory location that can hold different values at different times. It is like a box with a label.

In simple words: a variable is a labelled box in memory. Declaration makes the box, assignment puts a value inside, and later you can empty it and put a new value in.

Variables and Naming Rules

The naming rules (with valid and invalid examples)

RuleValidInvalid
Start with a letter or underscore_total, sum9marks (starts with digit)
No spaces or special symbols insidetotal_markstotal marks, a#b
Cannot be a keywordstudentint, if, for
C is case sensitivesum, Sum, SUM all different—

Program: declare, assign, change, print

Watch the full life of a variable — declare it, give it a value, change it, and print it at each stage:

Example03
Loading editor…
📝 Key Takeaways
  • A variable is a labelled box in memory that can hold different values.
  • Declaration makes the box: int age; — assignment puts a value in: age = 20.
  • Identifier rules: start with letter/underscore, no spaces/symbols, no keywords.
  • C is case sensitive — sum, Sum and SUM are three different variables.
  • You can change a variable's value any time: age = 25;

🧠 Test Your Knowledge

2 Questions
Progress: 0 / 2

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.