C Variable Values

C Tutorial

🔢 C Variable Values (Beginner → Advanced)

In C language, a variable value is the data stored inside a variable at a given time.
Understanding how values are assigned, updated, stored in memory, and accessed is essential for logic building, debugging, and interviews.


1️⃣ What is a Variable Value?

A variable value is the current data held by a variable.

int a = 10; // variable a holds value 10
  • a → variable name

  • 10 → variable value


2️⃣ Assigning Values to Variables ⭐

At Declaration

int x = 5;

After Declaration

int x;
x = 5;

✔ Both are valid


3️⃣ Changing (Updating) Variable Values 🔄

Variable values can change during program execution.

📌 C variables are mutable by default


4️⃣ Variable Values in Expressions ⭐


 

✔ Variable values are used in calculations


5️⃣ Variable Values with Different Data Types

Integer

int count = 100;

Floating-point

float price = 49.99;

Character

char grade = 'A';

📌 Each data type stores values differently in memory


6️⃣ Default (Garbage) Values ⚠️

Local Variables (Uninitialized)

int x;
printf("%d", x); // garbage value ❌

❌ Value is undefined


Global & Static Variables

✔ Automatically initialized to 0


7️⃣ Variable Values and Memory (Conceptual View)

int a = 10;

Memory (example):

Address: 1000 Value: 10

✔ Variable value is stored at a memory address


8️⃣ Variable Values via Pointers 🔥


 

✔ Pointer allows indirect access to variable value


9️⃣ Copying Variable Values (Call by Value)


 

a remains 10
b becomes 20


🔟 Modifying Values Using Functions ⭐

Call by Value (No Change)

Call by Reference (Change Original)


1️⃣1️⃣ Variable Values and Scope ⚠️


 

✔ Inner scope variable hides outer one


1️⃣2️⃣ Constants vs Variable Values

const int MAX = 100;
// MAX = 200; ❌ not allowed

✔ Variable values can change
✔ Constant values cannot


1️⃣3️⃣ Common Mistakes ❌

❌ Using uninitialized variables
❌ Assuming default value for local variables
❌ Confusing variable name with value
❌ Accidental overwrite of values
❌ Using wrong format specifier


📌 Interview Questions (Must Prepare)

  1. What is a variable value?

  2. What is garbage value?

  3. Difference between local and global variable values?

  4. How values are passed to functions?

  5. Can variable value change during execution?

  6. How pointers access variable values?


✅ Summary

✔ Variable value = data stored in variable
✔ Values can be assigned, updated, copied
✔ Local variables have no default value
✔ Global/static variables default to 0
✔ Pointers allow indirect access to values
✔ Fundamental for all C programs & interviews

You may also like...