C Variable Values
1. What is a Variable Value?
-
A variable value is the actual data stored in the memory location represented by a variable.
-
Variables can hold different values during program execution.
Example:
Output:
2. Initial Value vs. Assigned Value
-
Initialization → Assigning a value when the variable is declared:
-
Assignment → Giving a value to a variable after declaration:
3. Changing Variable Values
-
Variables in C are mutable, meaning you can update their values anytime in the program.
-
Can also use compound operators:
4. Example with Multiple Variables
Output:
5. Default Values of Variables
-
In C, local variables are not initialized by default.
-
They may contain garbage (random) values until you assign something.
-
Global and static variables are automatically initialized to 0 (for numbers) or
NULL(for pointers).
6. Key Points
-
Variable value can change anytime after declaration.
-
Always initialize local variables to avoid garbage values.
-
Use assignment operators for easy value updates.
