Master the fundamental building blocks of C programming. Learn how variables store data, manage memory addresses, and power your algorithms.
A variable is a named location in your computer's memory that stores a value. Think of it like a labeled box where you can put data.
The label you give the variable (e.g., score, age). Must start with a letter or underscore.
Defines what kind of data fits in the box (e.g., integer, character) and how much memory it needs.
The physical location in RAM (e.g., 0x7FF...) where the binary data is actually stored.
C provides fundamental types. Choosing the right one is crucial for memory efficiency.
Stores whole numbers without decimals.
Stores decimal numbers with single precision.
Higher precision decimal numbers.
Stores a single character or ASCII value.
Only positive numbers. Doubles positive range.
Represents "no type" or "nothing".
How to bring variables into existence. Always initialize to avoid garbage values.
age ≠ Age).
Understanding the physical storage. Every variable has an address in RAM.
Scope determines where a variable is visible and how long it lives.
| Scope Type | Declaration | Visibility | Lifetime |
|---|---|---|---|
| Local | Inside function | Only that function | Function execution |
| Global | Outside all | Entire Program | Program execution |
| Static | With 'static' kw | Only that function | Persists between calls |
| Parameter | Func arguments | Only that function | Function execution |
Uninitialized variables contain random garbage values. Always set a default like int x = 0;.
Use studentAge instead of sa or x. Use camelCase for variables and CAPS for constants.
Avoid global variables. They make debugging hard. Keep variables local to where they are used.
Putting it all together: Types, Initialization, Printing, and Logic.