आज आप इस Post में पढ़ने वाले हैं Data Type in C in Hindi में Detailed explanation और real code examples के साथ। C programming सीखते समय सबसे पहला और सबसे जरूरी concept जो आपको समझना होता है वह है Data Types — क्योंकि बिना data types को समझे आप एक भी सही program नहीं लिख सकते। हर variable जो आप declare करते हैं, हर value जो आप store करते हैं — उसके पीछे data type का concept काम करता है।
इस blog post में हम data types को बिल्कुल शुरुआत से सीखेंगे। आपको किसी advanced knowledge की जरूरत नहीं है — बस यह जानना काफी है कि C programming क्या होती है। हम सरल हिंदी भाषा में, step-by-step explanation और working code examples के साथ इस पूरे topic को cover करेंगे। हर data type को practically समझाया जाएगा ताकि आपको real programs में इसे use करने में कोई दिक्कत न हो।
इस post को पढ़ने के बाद आप जानेंगे कि Data Type in C क्या होता है, यह क्यों जरूरी है, कितने प्रकार के data types होते हैं, हर data type की size और range क्या होती है, format specifiers कैसे use होते हैं, और real programs में इन्हें कैसे apply किया जाता है। तो चलिए शुरू करते हैं!
Table of Contents
Data Type in C क्या होता है?
Data Type in C एक ऐसा keyword होता है जो compiler को यह बताता है कि किसी variable में किस तरह का data store होगा और उस data के लिए कितनी memory allocate करनी होगी। सरल भाषा में कहें तो — जब आप कोई variable बनाते हैं, तो आपको पहले यह तय करना होता है कि उसमें कौन से type की value रखी जाएगी — कोई पूरा number (integer), कोई decimal number (float), कोई अक्षर (character), या कोई और value।
उदाहरण के लिए:
- अगर आप किसी की उम्र store करना चाहते हैं → int use करेंगे
- अगर आप किसी की salary store करना चाहते हैं → float use करेंगे
- अगर आप किसी Student का grade store करना चाहते हैं → char use करेंगे
यही data type का मूल concept है — सही data के लिए सही type चुनना।
Data Type in C क्यों जरूरी है?
Data types निम्नलिखित कारणों से बेहद जरूरी हैं:
Memory Management: हर data type के लिए अलग-अलग memory allocate होती है। int के लिए 4 bytes, char के लिए 1 byte — यह compiler को पता होता है सिर्फ data type की वजह से।
Data Accuracy: सही data type use करने से calculations सही होती हैं। जैसे अगर आप decimal numbers को int में store करेंगे तो decimal part खो जाएगा।
Type Safety: C compiler data type check करता है और गलत operations पर error या warning देता है — जिससे program में bugs कम होते हैं।
Performance Optimization: छोटे data types (जैसे char, short) बड़े data types से कम memory use करते हैं, जो embedded systems में बहुत फर्क डालते हैं।
Data Types के प्रकार (Types of Data Types in C)
C language में data types को मुख्यतः तीन categories में बाँटा जाता है:
- Primary (Fundamental) Data Types
- Derived Data Types
- User-Defined Data Types
आइए इन्हें एक-एक करके विस्तार से समझते हैं।
1. Primary Data Types in C Programming
Primary data types वे basic building blocks हैं जो C language में पहले से defined होते हैं। इन्हें किसी और चीज़ से बनाया नहीं जाता — ये खुद ही fundamental होते हैं।
C Programming में चार primary data types होते हैं:
- int — Integer (पूर्ण संख्याएं)
- float — Floating-point (दशमलव संख्याएं)
- double — Double precision floating-point
- char — Character (अक्षर या symbol)
int Data Type (Integer)
int data type का use पूर्ण संख्याओं (whole numbers) को store करने के लिए होता है — जैसे age, roll number, marks आदि।
Size: 4 bytes (32-bit system पर)
Range: -2,147,483,648 से 2,147,483,647
Format Specifier: %d
Program Code:
#include <stdio.h>
int main() {
int age = 20; // Store age
int marks = 95; // Store marks
int temperature = -5; // Integer can also store negative values
printf("Age: %d\n", age);
printf("Marks: %d\n", marks);
printf("Temperature: %d\n", temperature);
return 0;
}
int के Modifiers: C में int के साथ modifiers use करके range और behavior बदला जा सकता है:
- short int — 2 bytes, range: -32,768 से 32,767
- long int — 4 या 8 bytes, बड़ी संख्याओं के लिए
- unsigned int — केवल positive values, 0 से 4,294,967,295
- signed int — positive और negative दोनों (default)
Program Code:
#include <stdio.h>
int main() {
short int s = 30000; // Short integer
long int l = 1234567890; // Long integer
unsigned int u = 4000000000U; // Unsigned integer
printf("Short int: %d\n", s);
printf("Long int: %ld\n", l);
printf("Unsigned int: %u\n", u);
return 0;
}
float Data Type (Floating-Point)
float data type का use decimal numbers (दशमलव संख्याओं) को store करने के लिए होता है — जैसे price, weight, percentage आदि।
Size: 4 bytes
Precision: लगभग 6-7 decimal digits
Format Specifier: %f
Program Code:
#include <stdio.h>
int main() {
float price = 199.99f; // Price value
float weight = 65.5f; // Weight value
float pi = 3.14159f; // Value of Pi
printf("Price: %.2f\n", price);
printf("Weight: %.1f\n", weight);
printf("Pi value: %.5f\n", pi);
return 0;
}
double Data Type
double data type भी decimal numbers store करने के लिए होता है, लेकिन float से ज्यादा precision के साथ। Scientific calculations में इसका use होता है।
Size: 8 bytes
Precision: लगभग 15-16 decimal digits
Format Specifier: %lf
Program Code:
#include <stdio.h>
int main() {
double exactPi = 3.14159265358979; // Double-precision floating-point value
double bigNumber = 1234567890.123456789; // Large decimal number
printf("Exact Pi: %.14lf\n", exactPi);
printf("Big Number: %.9lf\n", bigNumber);
return 0;
}
float और double में यही फर्क है — double ज्यादा accurate होता है। जब आपको high precision चाहिए (जैसे scientific या financial calculations में), तो double use करें।
char Data Type (Character)
char data type एक single character store करता है — जैसे कोई अक्षर, digit, या symbol C में characters को single quotes ‘ ‘ में लिखा जाता है।
Size: 1 byte
Range: -128 से 127 (signed) या 0 से 255 (unsigned)
Format Specifier: %c
Program Code:
#include <stdio.h>
int main() {
char grade = 'A'; // Character variable
char symbol = '#'; // Special symbol
char digit = '5'; // Character representing a digit
printf("Grade: %c\n", grade);
printf("Symbol: %c\n", symbol);
printf("Digit character: %c\n", digit);
// Display the ASCII value of a character
printf("ASCII value of '%c': %d\n", grade, grade);
return 0;
}
Important बात: C में char और int बहुत closely related हैं क्योंकि हर character की एक integer ASCII value होती है। ‘A’ = 65, ‘a’ = 97, ‘0’ = 48 — यह याद रखें।
2. Derived Data Types in C
Derived data types वे होते हैं जो primary data types से मिलकर बने होते हैं। इनमें शामिल हैं:
1. Array
Array एक ही type के multiple values को एक साथ store करता है।
Program Code:
#include <stdio.h>
int main() {
int marks[5] = {85, 90, 78, 92, 88}; // Array of 5 integer values
// Display all array elements
for (int i = 0; i < 5; i++) {
printf("marks[%d] = %d\n", i, marks[i]);
}
return 0;
}
2. Pointer
Pointer एक variable होता है जो किसी दूसरे variable के memory address store करता है।
Program Code:
#include <stdio.h>
int main() {
int num = 42; // Integer variable
int *ptr = &num ; // Pointer storing the address of num
printf("Value: %d\n", num);
printf("Address: %p\n", ptr);
printf("Value using pointer: %d\n", *ptr);
return 0;
}
3. Function In C
Functions भी derived data types का हिस्सा हैं — वे एक specific data type return करते हैं।
3. User-Defined Data Types in C
User-defined data types वे होते हैं जिन्हें programmer खुद define करते हैं। इनमें शामिल हैं:
1. Structure (struct)
Structure में अलग-अलग data types के variables को एक साथ group किया जाता है।
Program Code:
#include <stdio.h>
// Structure definition
struct Student {
char name[50]; // Student name
int age; // Student age
float percentage; // Student percentage
};
int main() {
struct Student s1; // Structure variable
// Assign values to structure members
s1.age = 18;
s1.percentage = 92.5f;
printf("Age: %d\n", s1.age);
printf("Percentage: %.2f\n", s1.percentage);
return 0;
}
2. Union In C Language
Union structure जैसा ही होता है, लेकिन इसमें सभी members एक ही memory location share करते हैं।
3. Enum (Enumeration)
Enum user-defined integer constants का set होता है।
Program Code:
#include <stdio.h>
// Enumeration for days of the week
enum Days {
Monday = 1,
Tuesday,
Wednesday,
Thursday,
Friday
};
int main() {
enum Days today = Wednesday; // Assign Wednesday to the variable
printf("Day number: %d\n", today);
return 0;
}

void Data Type — एक Special Type
void एक special data type है जिसका अर्थ होता है “कोई value नहीं।” इसके तीन main uses हैं:
Function return type: जब function कोई value return न करे।
void printMessage() {
printf("Hello, World!\n");
// कोई return statement नहीं
}
Function parameters: जब function कोई argument न ले।
int getNumber(void) {
return 42;
}
Void pointer: किसी भी type का address store करने के लिए।
void *ptr; // Generic pointer
C Data Types — Size, Range और System Architecture (32-bit)
C language में data types यह decide करते हैं कि किसी variable में किस प्रकार का data store होगा और memory में कितनी जगह लेगा। हर data type की एक fixed size (bytes में) और एक range होती है जो बताती है कि उसमें minimum और maximum कितनी value store हो सकती है। सही data type चुनना memory efficient program लिखने के लिए बहुत जरूरी है।
| Data Type | Size | Range | Format Specifier |
|---|---|---|---|
| char | 1 byte | -128 से 127 | %c / %hhd |
| unsigned char | 1 byte | 0 से 255 | %c / %hhu |
| short int | 2 bytes | -32,768 से 32,767 | %hd |
| int | 4 bytes | -2,147,483,648 से 2,147,483,647 | %d |
| unsigned int | 4 bytes | 0 से 4,294,967,295 | %u |
| long int | 4 bytes | -2,147,483,648 से 2,147,483,647 | %ld |
| unsigned long int | 4 bytes | 0 से 4,294,967,295 | %lu |
| float | 4 bytes | 1.2E-38 से 3.4E+38 | %f |
| double | 8 bytes | 2.3E-308 से 1.7E+308 | %lf |
sizeof() Operator — Data Type की Size कैसे पता करें?
C में sizeof() operator किसी भी data type या variable की memory size (bytes में) बताता है। यह बेहद useful होता है, खासकर जब हमें किसी data type का Size पता न हो और हमें उस data type का size जानना हो। निचे दिए गए program से समझ सकते हैं।
Program Code:
#include <stdio.h>
int main() {
// Display the size of different data types in bytes
printf("Size of char: %zu bytes\n", sizeof(char));
printf("Size of int: %zu bytes\n", sizeof(int));
printf("Size of short int: %zu bytes\n", sizeof(short int));
printf("Size of long int: %zu bytes\n", sizeof(long int));
printf("Size of float: %zu bytes\n", sizeof(float));
printf("Size of double: %zu bytes\n", sizeof(double));
printf("Size of long double: %zu bytes\n", sizeof(long double));
return 0;
}
Note: Memory Size को print करने के लिए %ZU Format Spcifier का use करते हैं।
Practical Example Program — सभी Data Types एक साथ
यह एक complete program है जो Data Type in C के सभी primary types को एक साथ demonstrate करता है — एक student record system के रूप में।
Program Code:
#include <stdio.h>
int main() {
// Student information stored using different data types
int rollNumber = 101;
char grade = 'A';
float percentage = 88.75f;
double totalScore = 1234567.89123456;
short int age = 19;
unsigned int attendance = 245;
printf("====== Student Record ======\n");
printf("Roll Number : %d\n", rollNumber);
printf("Age : %d\n", age);
printf("Grade : %c\n", grade);
printf("Percentage : %.2f%%\n", percentage);
printf("Total Score : %.8lf\n", totalScore);
printf("Attendance : %u days\n", attendance);
printf("\n====== Memory Sizes ======\n");
printf("int : %zu bytes\n", sizeof(rollNumber));
printf("char : %zu bytes\n", sizeof(grade));
printf("float : %zu bytes\n", sizeof(percentage));
printf("double : %zu bytes\n", sizeof(totalScore));
return 0;
}
Conclusion (निष्कर्ष )
आज आपने Data Type in C in Hindi में एक दम details में समझा। इस post में हमने देखा कि Primary Data Types (int, float, double, char) कैसे काम करते हैं, Derived और User-Defined Data Types क्या होते हैं, sizeof() operator कैसे use करते हैं, और format specifiers का सही उपयोग क्या है।
एक अच्छे programmer की पहचान यही है कि वह हर situation में सही data type चुने — न ज्यादा memory waste करे, न कम। अगर आप इन concepts को अच्छे से समझ लेते हैं, तो आगे के topics जैसे Arrays, Pointers और Structures सीखना बहुत आसान हो जाता है।
Practice ही सबसे बड़ा teacher है — ऊपर दिए गए सभी code examples को खुद run करें, output देखें, और values बदलकर experiment करें। यही तरीका है C programming में expert बनने का।
