C में Data Conversion क्या है?
C Language में Data Conversion एक ऐसा process है जिसमें एक data type को दूसरे data type में बदला जाता है। यह conversion जरूरी होता है जब हम अलग-अलग types की values के साथ calculation करते हैं या किसी function को specific type की value पास करनी होती है।
Table of Contents
उदाहरण:
अगर आप किसी integer value को float variable में assign करते हैं, तो compiler अपने आप उस int को float में convert कर देता है।
इसे Implicit Conversion कहा जाता है।
वहीं जब आप खुद manually type को बदलते हैं, तो उसे Explicit Conversion या Type Casting कहते हैं।

C Language में Data Conversion के प्रकार
- Implicit Conversion
- Explicit Conversion (Type Casting)
Implicit Conversion क्या है?
जब C compiler खुद-ब-खुद एक data type को दूसरे data type में convert कर देता है, उसे Implicit Conversion कहते हैं।
इसे Automatic Type Conversion या Type Promotion भी कहा जाता है।
कब होता है?
- जब दो अलग-अलग data types का उपयोग एक expression में हो
- या एक छोटे type को बड़े type में assign किया जाए
Example Code:
#include <stdio.h>
int main() {
int a = 10;
float b;
b = a; // int → float (implicit conversion)
printf("a (int): %d\n", a);
printf("b (float after conversion): %.2f\n", b);
return 0;
}
Explanation:
a एक int है, लेकिन जब उसे float variable b में assign किया गया, तो compiler ने उसे अपने आप float में बदल दिया।
कोई data loss नहीं हुआ, इसलिए यह safe conversion है।
Explicit Type Conversion in C (Manual / Forced)
यह क्या होता है?
जब programmer खुद तय करता है कि एक value को किस type में बदलना है, तो इसे Explicit Conversion या Type Casting कहते हैं।
इसमें हम type को manually specify करते हैं।
Syntax:
(target_type) value;
Example Code:
#include <stdio.h>
int main() {
float x = 15.75;
int y;
y = (int)x; // float → int (explicit conversion)
printf("x (float): %.2f\n", x);
printf("y (int after type casting): %d\n", y);
return 0;
}
Explanation:
हमने float को int में बदला, लेकिन decimal part (0.75) loss हो गया।
इसलिए explicit conversion हमेशा safe नहीं होता — इसे carefully use करना चाहिए।
Explicit Conversion का Real life Example
उदाहरण (Real-life analogy):
मान लो तुम्हारे पास 99.99 रुपये हैं (float), लेकिन तुम्हें सिर्फ ₹99 का सामान लेना है, यानी decimal हटाना है। तो तुम खुद पैसे काटकर ₹99 करते हो — ये काम तुम्हें manually करना पड़ा।
#include <stdio.h>
int main() {
// एक integer variable जिसमें items की संख्या store है
int items = 5;
// एक float variable जिसमें हर item की कीमत store है
float price_per_item = 19.99;
// total का calculation — यहाँ implicit conversion होगा (int से float)
float total = items * price_per_item; // items (int) को float में बदल दिया जाएगा automatically
// कुल bill को decimal के साथ print करना
printf("Total bill: %.2f\n", total); // %.2f मतलब 2 decimal तक दिखाओ
// अब हम float को int में manually cast कर रहे हैं — यह explicit conversion है
int roundedTotal = (int)total; // Decimal हिस्सा काट दिया जाएगा
// Rounded bill print करना (decimal हटाकर)
printf("Rounded bill to pay: %d\n", roundedTotal);
return 0;
}
C language में Data conversion (Implicit vs Explicit)
Point | Implicit Conversion | Explicit Conversion |
कौन करता है? | Compiler | Programmer |
Syntax | Automatic | (type)value required |
Data Loss का खतरा | बहुत कम | ज्यादा, especially decimals |
Example | float b = a; | int b = (int)f; |
Conclusion (निष्कर्ष)
अब आपको समझ आ चुका है कि C में Implicit और Explicit Type Conversion कैसे काम करता है।
याद रखें — जहां conversion automatic हो, वहां implicit conversion helpful होता है।
लेकिन जहां precision चाहिए, वहां explicit casting ज़रूरी हो जाती है।
अगर ये article आपके लिए helpful रहा हो, तो इसे ज़रूर शेयर करें और नीचे comment करके बताएं कि आपको कौन-सी चीज़ सबसे interesting लगी!
आगे आने वाले पोस्ट में हम Type Promotion और Real-world C examples cover करेंगे — जुड़ें रहें AnwarCodes के साथ।
Practice Quiz: Data Conversion in C Language (हिंदी में)
int a = 10;
float b = a;
A) Error आएगाB) Compiler खुद convert करेगा
C) Manually cast करना पड़ेगा
D) Program चलेगा ही नहीं
float x = 17.95;
int y = (int)x;
A) x और y दोनों float होंगेB) Decimal loss नहीं होगा
C) y की value 17 होगी
D) Compile error आएगा
B) float b = a;
C) int c = (int)4.89;
D) char d = ‘A’;
B) Manual Casting
C) Type Promotion
D) Format Specifier
B) Type Promotion
C) Explicit
D) Compiler Managed