1) Elementary Data Types:
Elementary ya primitive data types programming ke fundamental building blocks hote hain. Yeh kisi bhi programming language me sabse basic aur essential data types hote hain, jo memory allocation aur data manipulation me madad karte hain. Inka use complex data structures (arrays, lists, objects) banane ke liye bhi hota hai.
Integer ek aisa data type hai jo pure numbers (whole numbers) ko store karta hai.
Isme decimal point nahi hota (i.e., koi fractional value nahi hoti).
Yeh positive ya negative values bhi le sakta hai.
Example:
python CopyEdit
x = 10 # Positive integer
y = -5 # Negative integer
z = 1000 # Large integer
Memory usage:
Python me int ka size flexible hota hai (jitni memory chahiye, utni allocate hoti hai).
C/C++ me int ka fixed size hota hai (e.g., 4 bytes = 32-bit system me -2,147,483,648 se 2,147,483,647 tak values store ho sakti hain).
Floating-point numbers real numbers hote hain jo fractional part (decimal values) bhi store kar sakte hain.
float aur double me difference hota hai:
float (single precision) 4 bytes memory leta hai.
double (double precision) 8 bytes memory leta hai, aur zyada accurate hota hai.
Example:
python CopyEdit
a = 3.14 # Float number
b = -0.001 # Negative float
c = 2.718 # Mathematical constant
Use case: Scientific calculations, financial applications, graphics programming.
char ek single character ko represent karta hai, jo ASCII ya Unicode value me store hota hai.
Ek character single quotes (' ') me likha jata hai.
Example:
python CopyEdit
ch = 'A' # Character A
num = '9' # Number but stored as character
sym = '@' # Symbol
Memory Usage:
char usually 1 byte (8 bits) leta hai, jo 0-255 (ASCII values) ya Unicode characters ko represent kar sakta hai.
Example (ASCII values): 'A' = 65, 'a' = 97, '0' = 48
Boolean sirf do values store karta hai: True ya False.
Yeh mainly conditional statements aur decision making me use hota hai.
Example:
python CopyEdit
is_sunny = True
is_raining = False
Use case:
Comparisons & conditions:
python CopyEdit
x = 10
y = 20
print(x > y) # Output: False
Control Flow (if-else statements):
python CopyEdit
if is_sunny:
print("Wear sunglasses!")
else:
print("Carry an umbrella!")
String characters ka sequence hota hai, jo text store karne ke liye use hota hai.
Strings double quotes (" ") ya single quotes (' ') me likhe jate hain.
Example:
python CopyEdit
name = "Hello, World!"
word = 'Python'
Concatenation & Accessing Characters:
python CopyEdit
first = "Cyber"
second = "Security"
result = first + " " + second # Output: "Cyber Security"
print(name[0]) # Output: H
print(name[-1]) # Output: !
Use case: User input, file handling, web scraping, etc.
Elementary data types programming ke sabse basic aur essential blocks hote hain. Yeh data ko efficiently store aur manipulate karne me madad karte hain. Inhi data types ke upar complex data structures (arrays, lists, objects, dictionaries) build hote hain.
2) Enumeration:
Enumeration ya enum ek user-defined data type hai jo named values ka ek set define karta hai. Yeh mainly related constants ko group karne ke liye use hota hai, taaki code zyada readable aur maintainable ho sake.
Readability improve hoti hai: Numbers ki jagah meaningful names use kar sakte hain.
Maintainability easy hoti hai: Agar kisi constant ki value change karni ho toh sirf ek jagah update karni padti hai.
Error-prone code reduce hota hai: Hardcoded numbers use karne se confusion hoti hai, enum se ye problem solve ho jati hai.
Memory efficient hota hai: Default values integers hote hain, jo kam memory lete hain
C aur C++ me enum ek built-in feature hai jo integers ke liye symbolic names assign karta hai.
Example: Enum in C++
#include <iostream>
using namespace std;
enum Color { RED, GREEN, BLUE };
int main() {
Color myColor = RED;
cout << "My color is: " << myColor << endl; // Output: 0
return 0;
}
Explanation:
Color ek enum type hai jisme RED, GREEN, BLUE constants define kiye hain.
Default values 0, 1, 2 assign hoti hain.
Manually Assigning Values in Enum
cpp CopyEdit
enum Size { SMALL = 10, MEDIUM = 20, LARGE = 30 };
int main() {
Size tshirtSize = LARGE;
cout << "T-shirt size: " << tshirtSize << endl; // Output: 30
return 0;
}
Enum ek powerful concept hai jo related constants ko structured way me define karne me madad karta hai.
Yeh readability, maintainability aur type safety improve karta hai.
Alag-alag languages me enum ka implementation thoda different hota hai, but basic idea same rehta hai.
----------------------------
Kai programming languages me enum keyword ka use karke enumeration declare kiya jata hai.
Example:
enum Days {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};
Yahan Days ek enumerated type hai jo seven possible values ko represent karta hai.
Enumeration ke features:
Har enumerated constant ek integer value assign karta hai (default 0 se start hoti hai).
Enumerations code ko readable banate hain kyunki numeric literals ki jagah meaningful names hote hain.
Yeh errors ko kam karte hain kyunki variables predefined options me hi rakh sakte hain.
Enumerations commonly aise scenarios me use hote hain jaise states define karna (e.g., traffic lights) aur configuration options set karna.
3) Booleans:
Boolean data type sirf do values represent karta hai: true ya false. Boolean logic decision-making ke liye important hoti hai aur mostly conditional statements aur loops me use hoti hai.
Boolean ek data type hai jo sirf do values store karta hai:
True (1)
False (0)
Boolean logic decision-making ke liye sabse important hoti hai, kyunki ye conditions aur loops me use hoti hai.
Yeh decision-making me bohot zaroori hota hai, kyunki Boolean logic ko hum conditions aur loops me use karte hain. Jaise, agar hum kisi condition ko check kar rahe hain (jaise age check karna), toh hum True ya False values ke basis pe actions decide karte hain.
Example me dekho:
Agar kisi ki age 18 se zyada hai, toh True (sahi) hoga, matlab vote kar sakta hai. Agar 18 se kam hai, toh False (galat) hoga, matlab vote nahi kar sakta.
Boolean logic ka yeh hi main purpose hai: conditions ko True ya False me convert karke decision lena.
Code Example (Python):
# User ka age input lo
age = int(input("Apki umar kya hai? "))
# Boolean condition: agar age 18 ya usse zyada hai, toh True (sahi), warna False (galat)
can_vote = age >= 18
# Agar can_vote True hai, toh message dikhayenge "You can vote!"
if can_vote:
print("Aap vote kar sakte hain.")
else:
print("Aap vote nahi kar sakte.")
age >= 18 is a Boolean expression.
Agar age 18 ya usse zyada hai, toh condition True ho jayegi.
Agar age 18 se kam hai, toh condition False ho jayegi.
can_vote variable mein True ya False store hota hai, aur uske baad hum decision lete hain:
Agar True hai, toh user ko bataenge ki "Aap vote kar sakte hain."
Agar False hai, toh user ko bataenge ki "Aap vote nahi kar sakte."
Sample Output:
Agar user ki age 20 hai:
Apki umar kya hai? 20
Aap vote kar sakte hain.
Agar user ki age 16 hai:
Apki umar kya hai? 16
Aap vote nahi kar sakte.
Yeh ek simple practical example hai jisme humne Boolean ka use kiya hai decision-making ke liye.
4) Characters:
Character data type (char) ek single letter, digit, punctuation mark, ya special symbol ko represent karta hai. Characters encoding schemes jaise ASCII aur Unicode ka use karke store kiye jate hain.
char data type single character ko represent karta hai, jaise ek letter, digit, punctuation mark, ya special symbol. C me character ko store karne ke liye hum ASCII ya Unicode encoding schemes ka use karte hain.
ASCII encoding me har character ko ek unique number assign hota hai (0 se 127 tak).
Unicode ka use zyada complex characters (jaise emojis, foreign language characters) ko store karne ke liye hota hai.
Example (C me):
#include <stdio.h>
int main() {
// Character variable
char letter = 'A'; // Single character 'A' store kiya
char digit = '5'; // Single character '5' store kiya
char symbol = '@'; // Single special symbol '@' store kiya
// Print the characters
printf("Letter: %c\n", letter);
printf("Digit: %c\n", digit);
printf("Symbol: %c\n", symbol);
// Print the ASCII value of characters
printf("ASCII value of '%c' is: %d\n", letter, letter);
printf("ASCII value of '%c' is: %d\n", digit, digit);
printf("ASCII value of '%c' is: %d\n", symbol, symbol);
return 0;
}
char letter = 'A'; - Yeh statement 'A' character ko store karta hai.
printf function se hum characters ko print kar rahe hain.
ASCII values ko print karne ke liye %d format specifier use karte hain. Jaise:
'A' ka ASCII value 65 hota hai.
'5' ka ASCII value 53 hota hai.
'@' ka ASCII value 64 hota hai.
Letter: A
Digit: 5
Symbol: @
ASCII value of 'A' is: 65
ASCII value of '5' is: 53
ASCII value of '@' is: 64
char variable ek single character ko store karta hai.
Character ko ASCII ya Unicode ke roop me internally store kiya jata hai.
ASCII values ko %d specifier ke through print kiya ja sakta hai.