#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →

C में Data Type क्या है? Types और Examples (हिंदी में)

संक्षिप्त जवाब: C में data type compiler को बताता है कि किसी variable में किस तरह की value रखी जाएगी, उसे कितनी memory मिलेगी और उस पर कौन से operations हो सकते हैं। C में चार तरह के data types होते हैं: Primary (int, float, double, char), Derived (array, pointer, function), User-defined (struct, union, enum, typedef) और void।

C programming में हर variable का एक type होता है। जब आप int age = 21; लिखते हैं, तो compiler समझ जाता है कि age में एक whole number रहेगा और उसके लिए (आमतौर पर) 4 bytes memory चाहिए। सही data type चुनना memory बचाता है, errors रोकता है और program को तेज बनाता है।

लेखक: Mr. Bambam Kumar Yadav · Category: C Programming · पढ़ने का समय: 12 मिनट

Data type categories
4
int का typical size
4 bytes
double की precision
15–16 digits
unsigned int की max value
4,294,967,295

इस लेख में आप सीखेंगे

क्या?Data type क्या है और यह क्यों ज़रूरी है
TypesPrimary, Derived, User-defined और void data types (code examples के साथ)
Size & Rangeहर data type का size, range और format specifier
ModifiersType modifiers: short, long, signed, unsigned

साथ ही: Common mistakes, practice tips और FAQs।

C में Data Type क्या है?

Data type यह तय करता है कि variable में किस प्रकार का data (जैसे whole number, decimal number या character) store होगा। इसमें compiler को तीन बातें पता चलती हैं:

  • Variable के लिए कितनी memory allocate करनी है।
  • Memory में रखे bits को कैसे पढ़ना है (number, decimal या character)।
  • उस variable पर कौन से operations allowed हैं।

Data Types क्यों ज़रूरी हैं?

  • Efficient memory use: छोटी value के लिए char (1 byte) और बड़ी के लिए long long (8 bytes), ज़रूरत के हिसाब से memory।
  • Compile time पर error checking: गलत type की value assign करने पर compiler warning देता है।
  • Code readability: Type देखकर समझ आता है कि variable में क्या रखा है।
  • Performance: सही type से CPU calculations तेज होती हैं।

C में Data Types के प्रकार

Category Data Types
Primary (Built-in) int, float, double, char
Derived Array, Pointer, Function
User-defined struct, union, enum, typedef
Void void

1. Primary (Built-in) Data Types

Data Type Size (Typical) Range / Precision Format Specifier Example
int 4 bytes -2,147,483,648 से 2,147,483,647 %d int age = 21;
float 4 bytes लगभग 6–7 decimal digits precision %f float price = 99.50;
double 8 bytes लगभग 15–16 decimal digits precision %lf double pi = 3.14159;
char 1 byte -128 से 127 (या unsigned में 0 से 255) %c char grade = 'A';
#include <stdio.h> int main() { int age = 21; float price = 99.50f; double pi = 3.141592653589793; char grade = 'A'; printf("Age: %d\n", age); printf("Price: %.2f\n", price); printf("Pi: %.15lf\n", pi); printf("Grade: %c\n", grade); return 0; }

Output

Age: 21 Price: 99.50 Pi: 3.141592653589793 Grade: A

sizeof() से Size Check करना

Data type का exact size system और compiler पर निर्भर करता है। sizeof operator से आप अपने system पर size देख सकते हैं:

#include <stdio.h> int main() { printf("Size of char: %zu byte\n", sizeof(char)); printf("Size of short: %zu bytes\n", sizeof(short)); printf("Size of int: %zu bytes\n", sizeof(int)); printf("Size of long: %zu bytes\n", sizeof(long)); printf("Size of long long: %zu bytes\n", sizeof(long long)); printf("Size of float: %zu bytes\n", sizeof(float)); printf("Size of double: %zu bytes\n", sizeof(double)); return 0; }

Output (64-bit Linux/GCC पर)

Size of char: 1 byte Size of short: 2 bytes Size of int: 4 bytes Size of long: 8 bytes Size of long long: 8 bytes Size of float: 4 bytes Size of double: 8 bytes

Note: Windows (64-bit) पर long का size 4 bytes होता है, जबकि Linux/Mac (64-bit) पर 8 bytes। इसलिए portable code में बड़े numbers के लिए long long use करना बेहतर है।

2. Derived Data Types

Derived data types primary types से बनते हैं:

  • Array: Same type के कई elements का collection, जैसे int marks[5];
  • Pointer: किसी दूसरे variable का memory address store करता है, जैसे int *ptr;
  • Function: Function का return type भी एक type है, जैसे int add(int a, int b)
#include <stdio.h> int main() { int marks[5] = {85, 90, 78, 92, 88}; // Array (derived type) int *ptr = &marks[0]; // Pointer (derived type) printf("First mark: %d\n", marks[0]); printf("Using pointer: %d\n", *ptr); printf("Third mark via pointer: %d\n", *(ptr + 2)); return 0; }

Output

First mark: 85 Using pointer: 85 Third mark via pointer: 78

3. User-Defined Data Types

  • struct: अलग-अलग types के data को एक group में रखता है, जैसे किसी book का title, author और price।
  • union: struct जैसा, लेकिन सभी members एक ही memory share करते हैं, इसलिए एक समय में एक ही member की value valid रहती है।
  • enum: Named integer constants का set, जैसे हफ्ते के दिन।
  • typedef: किसी existing type को नया, छोटा नाम देता है।
#include <stdio.h> // struct: अलग-अलग types को एक group में रखना struct Book { char title[50]; char author[30]; float price; }; // enum: named integer constants enum Day { MON, TUE, WED, THU, FRI, SAT, SUN }; // typedef: किसी type को नया नाम देना typedef unsigned int uint; // union: सभी members एक ही memory share करते हैं union Data { int i; float f; }; int main() { struct Book b = {"C Programming Basics", "Uncodemy Team", 350.0f}; enum Day today = WED; uint count = 100; union Data d; printf("Book: %s by %s, Rs. %.2f\n", b.title, b.author, b.price); printf("Day number: %d\n", today); printf("Count: %u\n", count); d.i = 10; printf("Union int: %d\n", d.i); printf("Size of union: %zu bytes\n", sizeof(d)); return 0; }

Output

Book: C Programming Basics by Uncodemy Team, Rs. 350.00 Day number: 2 Count: 100 Union int: 10 Size of union: 4 bytes

enum में MON = 0 से गिनती शुरू होती है, इसलिए WED = 2। Union का size उसके सबसे बड़े member (int या float, दोनों 4 bytes) के बराबर है।

struct और union में अंतर

आधार struct union
Memory हर member को अलग memory सभी members एक ही memory share करते हैं
Size सभी members के size का जोड़ (padding के साथ) सबसे बड़े member के बराबर
Use सभी values एक साथ चाहिए हों एक समय में एक ही value चाहिए हो (memory बचाने के लिए)

4. void Data Type

void का मतलब है "कोई value नहीं"। इसका use तीन जगह होता है:

  • ऐसे function के लिए जो कुछ return नहीं करता: void greet() { printf("Hello"); }
  • ऐसे function के लिए जो कोई parameter नहीं लेता: int main(void)
  • Generic pointer के लिए: void *ptr; जो किसी भी type का address रख सकता है।

Type Modifiers: short, long, signed, unsigned

Modifiers किसी basic type का size या range बदलते हैं:

Modifier + Type Size (Typical) Range Format Specifier
short int 2 bytes -32,768 से 32,767 %hd
unsigned int 4 bytes 0 से 4,294,967,295 %u
long long int 8 bytes लगभग -9.2 × 10¹⁸ से 9.2 × 10¹⁸ %lld
unsigned char 1 byte 0 से 255 %c / %d
long double 10–16 bytes double से ज्यादा precision %Lf

signed type positive और negative दोनों values रखता है (default)। unsigned सिर्फ positive values रखता है, इसलिए उसकी positive range दोगुनी हो जाती है।

Real-Life Examples: कौन सा Data Type कहाँ?

Scenario सही Data Type क्यों
Age calculator int (या unsigned int) Age whole number है और negative नहीं होती
Temperature log float Decimal values (36.6°C) और negative भी हो सकती है
Student grade char 'A', 'B', 'C' जैसा एक character
Scientific calculation double ज्यादा precision चाहिए
Book details struct Title, author, price जैसे अलग-अलग types एक साथ
Population, bank transaction ID long long बहुत बड़े numbers

Common Mistakes जो Beginners करते हैं

नीचे का program दो common गलतियाँ दिखाता है:

#include <stdio.h> int main() { unsigned char small = 300; // range 0 se 255 int a = 7, b = 2; printf("unsigned char में 300 store किया: %d\n", small); printf("int division 7 / 2 = %d\n", a / b); printf("float casting 7 / 2 = %.1f\n", (float)a / b); return 0; }

Output

unsigned char में 300 store किया: 44 int division 7 / 2 = 3 float casting 7 / 2 = 3.5
  • Range से बड़ी value store करना: unsigned char की range 0–255 है। 300 डालने पर value wrap होकर 300 – 256 = 44 बन जाती है।
  • Integer division: दो int को divide करने पर decimal हिस्सा कट जाता है (7 / 2 = 3)। सही result के लिए type casting करें: (float)a / b
  • Money के लिए float use करना: float में rounding errors आते हैं। Currency को paise में int/long long में रखें या double का ध्यान से use करें।
  • Always-positive values के लिए unsigned भूलना: Count या index जैसी values के लिए unsigned बेहतर range देता है।
  • गलत format specifier: double के लिए scanf में %f लिखना (सही है %lf)।
  • Loop counter का type mismatch: unsigned और signed values की तुलना से अजीब bugs आ सकते हैं।

Practice Tips

  • ऐसे programs लिखें जिनमें int, float, char और double सब एक साथ use हों।
  • Type casting के साथ experiment करें (int से float, float से int)।
  • sizeof() से अपने system पर हर type का size खुद check करें।
  • Debugger (जैसे GDB या IDE का debugger) से variables की memory और values देखें।

C Data Types से जुड़े FAQs

Q1. C में data type क्या है?

Data type compiler को बताता है कि variable में किस तरह की value रहेगी, उसे कितनी memory मिलेगी और उस पर कौन से operations हो सकते हैं।

Q2. C में कितने प्रकार के data types होते हैं?

चार प्रकार: Primary (int, float, double, char), Derived (array, pointer, function), User-defined (struct, union, enum, typedef) और void।

Q3. C में int का size कितना होता है?

ज्यादातर modern 32-bit और 64-bit systems पर int 4 bytes का होता है, लेकिन exact size compiler पर निर्भर करता है। sizeof(int) से check करें।

Q4. float और double में क्या अंतर है?

float आमतौर पर 4 bytes का होता है और लगभग 6–7 digits precision देता है, जबकि double 8 bytes का होता है और लगभग 15–16 digits precision देता है।

Q5. struct और union में क्या अंतर है?

struct में हर member को अलग memory मिलती है, जबकि union के सभी members एक ही memory share करते हैं। इसलिए union का size उसके सबसे बड़े member के बराबर होता है।

Q6. void data type का use कहाँ होता है?

जो function कुछ return नहीं करता, जो function कोई parameter नहीं लेता, और generic pointer (void *) में void use होता है।

Q7. unsigned int और int में क्या अंतर है?

int positive और negative दोनों values रखता है, जबकि unsigned int सिर्फ positive values (0 से 4,294,967,295) रखता है।

Q8. C में double के लिए कौन सा format specifier use होता है?

scanf() में double के लिए %lf ज़रूरी है। printf() में %f और %lf दोनों काम करते हैं।

Key Takeaways

  • Data type बताता है कि variable में कैसी value रहेगी और उसे कितनी memory मिलेगी।
  • C में 4 categories हैं: Primary, Derived, User-defined और void।
  • int (%d), float (%f), double (%lf) और char (%c) सबसे basic types हैं।
  • short, long, signed और unsigned modifiers size और range बदलते हैं।
  • Data type का size system पर निर्भर करता है, sizeof() से check करें।

निष्कर्ष (Conclusion)

Data types C programming की नींव हैं। सही data type चुनने से program कम memory लेता है, तेज चलता है और bugs कम होते हैं। Primary types से शुरुआत करें, फिर arrays, pointers और structures की तरफ बढ़ें। Type सोच-समझकर चुनिए, code अपने आप बेहतर होगा।

C programming को basics से advanced तक, projects के साथ सीखना चाहते हैं? Uncodemy का C Programming Course देखें।

Related Hindi Guides

नीचे दिए Hindi pages live होने के बाद इस blog में contextual links जोड़ें — जो page अभी live नहीं है, उसका link न डालें (404 से बचें)।

Topic Planned URL
C में Array /hi/blog/what-is-array-in-c-language-types-and-examples
C के 32 Keywords /hi/blog/thirty-two-important-keywords-in-c-language
C में दो Numbers का Sum /hi/blog/sum-of-two-numbers-in-c-with-input-and-output-example
Armstrong Number /hi/blog/what-is-armstrong-number-definition-and-c-program

Visit Us

Delhi Centre Address
2nd & 3rd Floor, Maa Katyayni Complex, MB-1E, Madhuban Rd, next to DSEU Ambedkar College, Laxmi Nagar, Shakarpur Extension, Shakarpur, Delhi, 110092
Opening hours
Monday – Sunday, 06:00 – 22:30
Website
uncodemy.com