Variables, Data Types aur Input/Output
Agar aap C++ programming seekh rahe ho, toh sabse pehla step hota hai variables, data types, aur input/output (I/O) ko samajhna. Ye concepts programming ki foundation hote hain.
Variables kya hote hain?
Variable ek aisi memory location hoti hai jisme hum data store kar sakte hain. Jaise ek box jisme aap kuch bhi rakh sakte ho. Variable ka naam hota hai jiske through hum us data ko access karte hain.
Variable Declare aur Initialize kaise karein?
int age; // Declaration
age = 20; // Initialization
// Declaration and Initialization
int marks = 95;
Basic Data Types in C++
C++ mein kuch common data types hote hain jinke through hum different types ka data store karte hain.
int
: Integer values
Example: int roll = 101;
float
: Float Values
Exmaple: float pi = 3.14;
char
: Single character
Example:
char grade = 'A';
bool
: True or False
Example: bool passed = true;
Example Code:
#include <iostream>
using namespace std;
int main() {
int age = 21;
float height = 5.9;
char initial = 'S';
bool isStudent = true;
cout << "Age: " << age << endl;
cout << "Height: " << height << endl;
cout << "Initial: " << initial << endl;
cout << "Is Student: " << isStudent << endl;
return 0;
}
Output:
Age: 21
Height: 5.9
Initial: S
Is Student: true
Input/Output in C++ (I/O)
C++ mein hum cin
aur cout
ka use karte hain:
cout
– Console par data print karne ke liye.cin
– User se input lene ke liye.
Input
int age;
cout << "Enter your Age: ";
cin >> age;
cout << "Your Age is: " << age << endl;
Remembers
- Variable name meaningful rakho (
marks
,salary
, etc.). char
mein hamesha single quotes use karo ('A'
not"A"
).bool
ka output1
hota hai fortrue
, aur0
forfalse
.
Conclusion
So guys, in this blog we have learned:
- Variable kya hota hai aur kaise banate hain
- Common data types ka use kaise hota hai
- Input aur output kaise lete hain C++ mein
Comments