🟢 Foundation · Lesson 07
Variables and Data Types in C++
Variables and Data Types in C++
What is Variables and Data Types in C++?
Variables and Data Types in C++
A variable is a named memory location used to store data. Data type tells the compiler what kind of value will be stored and how much memory may be needed.
A variable is a named memory location used to store data. Data type tells the compiler what kind of value will be stored and how much memory may be needed.
Level
🟢 Beginner – C++ Foundation
🟢 Beginner – C++ Foundation
Example File
variables-data-types.cppMain Focus
Concept + syntax + practical C++ program
Concept + syntax + practical C++ program
Why should you learn this?
- It helps you write correct and readable C++ programs.
- It is used repeatedly in school practicals, projects and competitive programming.
- It builds the base for advanced topics such as OOP, STL and data structures.
Important Terms
| Term | Meaning / Use |
|---|---|
| int | Variables and Data Types in C++ programming में Int use होता है। |
| float | Variables and Data Types in C++ programming में Float use होता है। |
| double | Variables and Data Types in C++ programming में Double use होता है। |
| char | Variables and Data Types in C++ programming में Char use होता है। |
| bool | Variables and Data Types in C++ programming में Bool use होता है। |
| string | Variables and Data Types in C++ programming में String use होता है। |
Syntax / Pattern
C++
data_type variable_name = value;
Example Program
main.cpp
#include <iostream>
using namespace std;
int main() {
int age = 16;
double percentage = 92.5;
char grade = 'A';
bool passed = true;
cout << age << " " << percentage << " " << grade << " " << passed;
return 0;
}Expected Output
16 92.5 A 1
Program Explanation
- bool true is printed as 1 by default.
- double stores decimal values with better precision than float.
- char stores a single character.
Exam Tip: In C++ practical answers, write the logic first, then the program, then expected output. For theory, always include one suitable example.
Where will you use it?
- student records
- fee calculation
- marks and percentage
- conditions
Common Mistakes
- Using int for decimal values.
- Using single quotes for full strings.
- Using invalid variable names with spaces.
Practice Tasks
- Create variables for roll number, name, marks and grade.
- Print size of different data types using sizeof().
Summary
Variables and Data Types in C++ एक ज़रूरी C++ topic है। परिभाषा सीखें, syntax समझें, example program चलाएं और फिर practice tasks हल करके concept मज़बूत करें।
Variables and Data Types in C++ क्या है?
Variables and Data Types in C++
A variable is a named memory location used to store data. Data type tells the compiler what kind of value will be stored and how much memory may be needed.
A variable is a named memory location used to store data. Data type tells the compiler what kind of value will be stored and how much memory may be needed.
Level
🟢 Beginner – C++ Foundation
🟢 Beginner – C++ Foundation
Example File
variables-data-types.cppमुख्य फोकस
Concept + syntax + practical C++ program
Concept + syntax + practical C++ program
इसे क्यों सीखें?
- यह आपको सही और पढ़ने-योग्य C++ programs लिखने में मदद करता है।
- यह school practicals, projects और competitive programming में बार-बार use होता है।
- यह OOP, STL और data structures जैसे advanced topics की नींव बनाता है।
ज़रूरी Terms
| Term | अर्थ / उपयोग |
|---|---|
| int | Int Variables and Data Types in C++ programming में use होता है। |
| float | Float Variables and Data Types in C++ programming में use होता है। |
| double | Double Variables and Data Types in C++ programming में use होता है। |
| char | Char Variables and Data Types in C++ programming में use होता है। |
| bool | Bool Variables and Data Types in C++ programming में use होता है। |
| string | String Variables and Data Types in C++ programming में use होता है। |
Syntax / Pattern
C++
data_type variable_name = value;
Example Program
main.cpp
#include <iostream>
using namespace std;
int main() {
int age = 16;
double percentage = 92.5;
char grade = 'A';
bool passed = true;
cout << age << " " << percentage << " " << grade << " " << passed;
return 0;
}Expected Output
16 92.5 A 1
Program Explanation
- bool true is printed as 1 by default.
- double stores decimal values with better precision than float.
- char stores a single character.
Exam Tip: In C++ practical answers, write the logic first, then the program, then expected output. For theory, always include one suitable example.
Where will you use it?
- student records
- fee calculation
- marks and percentage
- conditions
आम गलतियाँ (Common Mistakes)
- Using int for decimal values.
- Using single quotes for full strings.
- Using invalid variable names with spaces.
अभ्यास (Practice Tasks)
- Create variables for roll number, name, marks and grade.
- Print size of different data types using sizeof().
सारांश
Variables and Data Types in C++ एक ज़रूरी C++ topic है। परिभाषा सीखें, syntax समझें, example program चलाएं और फिर practice tasks हल करके concept मज़बूत करें।
💻 Live Code Editor
Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें.
Agar load na ho to naye tab mein kholें.