Data Type in c in hindi
/ BCA / Programming with C and CPP
Data Types in C in Hindi
C Language में Data Types क्या होते हैं (Data Types in C Language in Hindi)
C Language एक programming language है जिसमें variables को define करते समय यह बताना जरूरी होता है कि वो किस प्रकार का data store करेगा। यहीं से Data Type का concept आता है। Data Type यह निर्धारित करता है कि किसी variable में कौन सी value store होगी, वह memory में कितनी जगह लेगा, और उस पर कौन से operations perform किए जा सकते हैं।
What is Data Type (डेटा टाइप क्या है?)
Data Type का मतलब होता है — “डेटा का प्रकार” यानी यह बताता है कि किसी variable में किस तरह का data store किया जाएगा। उदाहरण के लिए —
int– integers (पूरा अंक) store करने के लिए।float– decimal numbers (दशमलव मान) के लिए।char– single character (जैसे 'A', 'b', '1') के लिए।
int age = 25;
float price = 59.75;
char grade = 'A';
ऊपर के उदाहरण में — age integer है, price floating-point number है और grade एक character है।
Types of Data Types in C (C में Data Types के प्रकार)
C Language में Data Types को तीन मुख्य categories में बांटा गया है —
- Basic (Primary) Data Types
- Derived Data Types
- User-Defined Data Types
Basic Data Types in C (मूल डेटा टाइप)
C Language के Basic Data Types वे data types होते हैं जो language के अंदर पहले से मौजूद (predefined) होते हैं। इनका इस्तेमाल किसी variable में simple data जैसे — numbers, characters, floating point values आदि store करने के लिए किया जाता है। C में कुल पाँच मुख्य basic data types होते हैं — int, char, float, double और void।
Basic Data Types Table (सभी डेटा टाइप्स का आकार और रेंज)
| Data Type | Size (in Bytes) | Range | Format Specifier | Example |
|---|---|---|---|---|
| int | 4 Bytes | -2,147,483,648 to 2,147,483,647 | %d | int age = 25; |
| char | 1 Byte | -128 to 127 | %c | char grade = 'A'; |
| float | 4 Bytes | 3.4E-38 to 3.4E+38 | %f | float salary = 12345.75; |
| double | 8 Bytes | 1.7E-308 to 1.7E+308 | %lf | double value = 1234567.1234; |
| void | 0 Bytes | कोई value store नहीं करता | कोई नहीं | void display(); |
1. int Data Type (इंटीजर डेटा टाइप)
int का इस्तेमाल integer यानी पूर्णांकों (whole numbers) को store करने के लिए किया जाता है। यह decimal points को store नहीं करता। C language में int सबसे commonly used data type है।
Syntax:
int variable_name = value;
Example:
int age = 20;
printf("Age is %d", age);
Output:
Age is 20
Facts:
- int का size system architecture (16-bit, 32-bit, 64-bit) पर depend करता है।
- Modern compilers में इसका size अधिकतर 4 Bytes होता है।
- Range: -2,147,483,648 से 2,147,483,647 तक होती है।
2. char Data Type (कैरेक्टर डेटा टाइप)
char का उपयोग single character को store करने के लिए किया जाता है। यह characters को single quotes (' ') में रखता है और internally उनके ASCII value को store करता है।
Syntax:
char variable_name = 'character';
Example:
char grade = 'A';
printf("Grade: %c", grade);
Output:
Grade: A
Facts:
- char का size 1 Byte होता है।
- यह -128 से 127 तक integer values store कर सकता है (signed form में)।
- ASCII value ‘A’ = 65 और ‘a’ = 97 होती है।
3. float Data Type (फ्लोटिंग पॉइंट डेटा टाइप)
float data type का उपयोग decimal (दशमलव) values को store करने के लिए किया जाता है। यह real numbers को represent करता है, जैसे 3.14, 12.65, -0.001 आदि।
Syntax:
float variable_name = value;
Example:
float salary = 35600.50;
printf("Salary = %f", salary);
Output:
Salary = 35600.500000
Facts:
- float का size 4 Bytes होता है।
- इसकी precision लगभग 6 decimal digits तक होती है।
- Range: 3.4 × 10-38 से 3.4 × 10+38 तक होती है।
4. double Data Type (डबल डेटा टाइप)
double का उपयोग तब किया जाता है जब हमें float से भी अधिक precision की जरूरत होती है। यह double precision floating-point numbers को store करता है।
Syntax:
double variable_name = value;
Example:
double distance = 123456.789;
printf("Distance = %lf", distance);
Output:
Distance = 123456.789000
Facts:
- double का size 8 Bytes होता है।
- यह 15 से 16 decimal digits तक precision प्रदान करता है।
- Range: 1.7 × 10-308 से 1.7 × 10+308 तक होती है।
5. void Data Type (वॉइड डेटा टाइप)
void का मतलब होता है — “कुछ नहीं”। यह ऐसा data type है जो value store नहीं करता। अक्सर इसका उपयोग functions में किया जाता है जहाँ return type नहीं होता।
Syntax:
void function_name();
Example:
void display() {
printf("Hello C Language");
}
Output:
Hello C Language
Facts:
- void का size 0 Bytes होता है।
- यह variable type के रूप में इस्तेमाल नहीं किया जा सकता।
- Function के return type या pointer type में इसका उपयोग किया जाता है।
Additional Information:
| Modifier | Used With | Description |
|---|---|---|
| short | int | छोटे integer range के लिए (2 Bytes) |
| long | int, double | बड़े integer या float range के लिए |
| unsigned | int, char | Positive values के लिए (negative values नहीं लेता) |
| signed | int, char | Negative और Positive दोनों values store कर सकता है |
Derived Data Types in C (व्युत्पन्न डेटा टाइप)
Derived Data Types वे data types हैं जो Basic Data Types से बनाए जाते हैं। इनका उपयोग तब किया जाता है जब हमें complex data structures को manage करना होता है — जैसे array, pointer, structure या union। C Language में चार मुख्य derived data types होते हैं:
- Array (एरे)
- Pointer (पॉइंटर)
- Structure (स्ट्रक्चर)
- Union (यूनियन)
Derived Data Types Table
| Derived Data Type | Description | Syntax | Example |
|---|---|---|---|
| Array | एक जैसे data items को store करने के लिए | data_type array_name[size]; | int marks[5]; |
| Pointer | Variable का memory address store करने के लिए | data_type *pointer_name; | int *ptr; |
| Structure | विभिन्न data types को combine करने के लिए | struct structure_name { ... }; | struct student { int id; char name[20]; }; |
| Union | Memory share करने के लिए (एक समय में एक value) | union union_name { ... }; | union data { int i; float f; }; |
1. Array in C (एरे)
Array एक collection होता है एक जैसे type के elements का, जो memory में sequentially store होते हैं। Array का उपयोग तब किया जाता है जब हमें एक ही type के multiple values को एक साथ store करना होता है।
Syntax:
data_type array_name[size];
Example:
int marks[5] = {85, 90, 75, 80, 95};
printf("First mark = %d", marks[0]);
Output:
First mark = 85
Facts:
- Array का size हमेशा integer में define किया जाता है।
- Array index 0 से शुरू होता है।
- 2D Arrays (Matrix form) भी बनाए जा सकते हैं जैसे
int matrix[3][3];
2. Pointer in C (पॉइंटर)
Pointer एक special variable होता है जो किसी दूसरे variable का memory address store करता है। इसका उपयोग dynamic memory allocation और indirect data access के लिए किया जाता है।
Syntax:
data_type *pointer_name;
Example:
int a = 10;
int *ptr = &a;
printf("Value of a = %d", *ptr);
Output:
Value of a = 10
Facts:
- ‘&’ (Address-of) operator variable का address देता है।
- ‘*’ (Dereference) operator pointer के stored address की value देता है।
- Pointers memory-efficient programs बनाने में मदद करते हैं।
3. Structure in C (स्ट्रक्चर)
Structure एक user-defined data type होता है जो अलग-अलग data types को एक साथ group करता है। इसका उपयोग real-world entities जैसे student, employee आदि के data को logically represent करने के लिए किया जाता है।
Syntax:
struct structure_name {
data_type member1;
data_type member2;
};
Example:
struct student {
int id;
char name[20];
float marks;
};
struct student s1 = {1, "Amit", 88.5};
printf("ID: %d, Name: %s, Marks: %.2f", s1.id, s1.name, s1.marks);
Output:
ID: 1, Name: Amit, Marks: 88.50
Facts:
- Structure में अलग-अलग data types store किए जा सकते हैं।
- Structure variables को access करने के लिए dot (.) operator का use होता है।
- Structures memory में total members के size का sum लेते हैं।
4. Union in C (यूनियन)
Union भी structure की तरह होता है, लेकिन यह सभी members के लिए shared memory space allocate करता है। इसका मतलब है कि एक समय में केवल एक member की value store होती है।
Syntax:
union union_name {
data_type member1;
data_type member2;
};
Example:
union data {
int i;
float f;
char str[20];
};
union data d1;
d1.i = 10;
printf("i = %d\\n", d1.i);
d1.f = 22.5;
printf("f = %.2f\\n", d1.f);
Output:
i = 10
f = 22.50
Facts:
- Union का size उसके सबसे बड़े member के size के बराबर होता है।
- Union memory-efficient होता है क्योंकि यह space share करता है।
- एक समय में केवल एक variable की value valid रहती है।
Additional Facts about Derived Data Types:
| Data Type | Use | Memory Nature |
|---|---|---|
| Array | Similar type values store करता है | Continuous memory allocation |
| Pointer | Memory address handle करता है | Dynamic access |
| Structure | Different type variables combine करता है | Separate memory for each member |
| Union | Shared memory में data रखता है | Memory saving mechanism |
User-Defined Data Types in C (यूज़र द्वारा परिभाषित डेटा टाइप)
C Language में User-Defined Data Types वे data types होते हैं जिन्हें programmer खुद define कर सकता है। इनका मुख्य उद्देश्य होता है – existing data types को logically organize करना, meaningful names देना, और complex data को manage करना। C में user-defined data types प्रोग्राम को अधिक readable और structured बनाते हैं।
C Language में तीन प्रमुख User-Defined Data Types होते हैं:
- Structure (struct)
- Union (union)
- Enumeration (enum)
- typedef (Type Definition)
User-Defined Data Types Table
| Data Type | Description | Syntax | Example |
|---|---|---|---|
struct |
अलग-अलग data types को combine करता है | struct structure_name { ... }; |
struct student { int id; char name[20]; }; |
union |
एक memory location share करता है | union union_name { ... }; |
union data { int i; float f; }; |
enum |
Named integer constants define करता है | enum enum_name { const1, const2, ... }; |
enum week { Sun, Mon, Tue }; |
typedef |
Existing data type को नया नाम देता है | typedef existing_type new_name; |
typedef int number; |
1. Structure in C (स्ट्रक्चर)
Structure एक user-defined data type है जिसमें अलग-अलग types के variables को एक साथ store किया जा सकता है। इसका उपयोग complex data को represent करने के लिए किया जाता है, जैसे किसी student या employee की details।
Syntax:
struct structure_name {
data_type member1;
data_type member2;
...
};
Example:
struct student {
int id;
char name[20];
float marks;
};
struct student s1 = {1, "Ravi", 92.5};
printf("ID: %d, Name: %s, Marks: %.2f", s1.id, s1.name, s1.marks);
Output:
ID: 1, Name: Ravi, Marks: 92.50
Facts:
- Structure variables को access करने के लिए dot (.) operator का प्रयोग किया जाता है।
- Structure अलग-अलग data types को logically group करता है।
- यह memory में हर member के लिए अलग जगह allocate करता है।
2. Union in C (यूनियन)
Union structure की तरह ही होता है, लेकिन यह सभी members के लिए shared memory का उपयोग करता है। इससे memory saving होती है क्योंकि एक समय में केवल एक member की value valid रहती है।
Syntax:
union union_name {
data_type member1;
data_type member2;
};
Example:
union data {
int i;
float f;
char str[10];
};
union data d1;
d1.i = 100;
printf("i = %d\\n", d1.i);
d1.f = 25.5;
printf("f = %.2f", d1.f);
Output:
i = 100
f = 25.50
Facts:
- Union का size उसके सबसे बड़े member के size के बराबर होता है।
- यह memory-efficient होता है लेकिन data overwrite हो सकता है।
- Dot (.) operator से union members को access किया जाता है।
3. Enumeration in C (एनुमरेशन)
Enumeration (enum) का उपयोग named integer constants define करने के लिए किया जाता है। यह readability बढ़ाता है और code को समझने में आसान बनाता है।
Syntax:
enum enum_name { const1, const2, const3, ... };
Example:
enum week { Sun, Mon, Tue, Wed, Thu, Fri, Sat };
enum week today;
today = Wed;
printf("Day: %d", today);
Output:
Day: 3
Facts:
- By default, पहला constant का value 0 से शुरू होता है।
- आप manually भी values दे सकते हैं जैसे
enum week { Sun=1, Mon=2 }; - Enum code readability को बढ़ाने में मदद करता है।
4. typedef in C (टाइपडिफ)
typedef keyword का उपयोग किसी existing data type को नया नाम देने के लिए किया जाता है। यह complex declarations को simplify करता है और code readability बढ़ाता है।
Syntax:
typedef existing_type new_type_name;
Example:
typedef int number;
number x = 25;
printf("Value: %d", x);
Output:
Value: 25
Facts:
typedefका मतलब “type definition” होता है।- यह struct या pointer जैसे complex types को छोटा नाम देने में helpful होता है।
- उदाहरण:
typedef struct student STU;अबSTU s1;से structure define किया जा सकता है।
Additional Table: Difference Between struct, union, enum, typedef
| Feature | struct | union | enum | typedef |
|---|---|---|---|---|
| Memory Allocation | प्रत्येक member को अलग memory | सभी members एक ही memory share करते हैं | Values integer के रूप में assign होती हैं | Memory पर कोई प्रभाव नहीं |
| Keyword Used | struct | union | enum | typedef |
| Purpose | Different data combine करना | Memory save करना | Named constants define करना | Data type को नया नाम देना |
| Access Operator | Dot (.) | Dot (.) | Constant name | Type name |