CPP Variables Examples

C++ Tutorial

💻 CPP Variables Examples (Beginner → Interview Ready)

Below are clear, exam-oriented examples showing how variables work in CPP Variables Examples along with their outputs.


1️⃣ Integer Variable Example ⭐


 

Output

20

2️⃣ Float Variable Example ⭐


 

Output

85.5

3️⃣ Character Variable Example ⭐


 

Output

A

4️⃣ String Variable Example ⭐


 

Output

Sanjit

5️⃣ Multiple Variables Example ⭐⭐


 

Output

10 20

6️⃣ Changing Variable Value ⭐


 

Output

25

7️⃣ Variable with Calculation ⭐⭐


 

Output

50

8️⃣ Local Variable Example ⭐⭐


 

Output

5

9️⃣ Global Variable Example ⭐⭐


 

Output

100

🔟 Static Variable Example ⭐⭐⭐


 

Output

1 2 3

1️⃣1️⃣ Constant Variable Example ⭐⭐


 

Output

50

📌 Common Exam Questions (Variables)

Q1. Can variable value change?
👉 Yes (except const)

Q2. Are variable names case-sensitive?
👉 Yes

Q3. What is a static variable?
👉 Retains value between function calls


✅ Summary

✔ Variables store data
✔ Must be declared before use
✔ Can change values (except constants)
✔ Types: local, global, static, const
✔ Used in calculations & logic

You may also like...