Variables and Data Types in C in Hindi – C के Data Types और Variables समझें

नमस्कार दोस्तों! C में Input/Output सीखने के बाद अगला सबसे ज़रूरी कॉन्सेप्ट है Variables and Data Types in C in Hindi
Variables डेटा को स्टोर करने का काम करते हैं, और Data Types कंपाइलर को बताते हैं कि उस डेटा को कैसे समझना (interpret) है।

इस गाइड में आप सीखेंगे:

  • Variables क्या होते हैं C में
  • अलग-अलग Data Types को समझना
  • Declaration और Initialization के उदाहरण देखना
  • Common mistakes और best practices जानना

तो चलिए शुरू करते हैं


C में Variables क्या होते हैं? – Variables and Data Types in C in Hindi

Variable एक ऐसा नाम (identifier) है जो memory location को represent करता है जहाँ पर data store किया जाता है।
किसी भी variable को use करने से पहले उसे declare करना ज़रूरी होता है।

सीधी भाषा में: Variable memory ka वह नाम है जिसमें कुछ data store होता है।

उदाहरण:

int age;        // variable declaration
age = 25;       // value assign करना
printf("Age: %d\n", age);   // output: Age: 25

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

Data Types यह तय करते हैं:

  • एक variable कितनी memory लेगा
  • उस variable पर कौन-कौन से operations allowed होंगे
  • values को किस तरह interpret किया जाएगा

सही data type का इस्तेमाल करने से type safety बनी रहती है और memory का efficient use होता है।


Types Of Data Types In C – C में Data Types के प्रकार

1. int

  • पूरे अंक (whole numbers) store करता है
  • Size: लगभग 4 bytes
  • Range: -2,147,483,648 से 2,147,483,647 तक
int score = 90;

2. float

  • Decimal numbers (दशमलव वाले अंक) store करता है
  • Size: लगभग 4 bytes
  • Precision: ~7 decimal digits तक
float temperature = 36.5;

3. double

  • float से ज़्यादा precision (अधिक सटीकता) provide करता है
  • Size: 8 bytes
  • Precision: ~15 decimal digits तक
double balance = 1000.50;

4. char

  • एक single character store करता है
  • Size: 1 byte
  • Range: -128 से 127 (या 0 से 255 अगर unsigned हो)
char grade = 'A';

5. अन्य प्रकार (short, long, long long)

तब use किए जाते हैं जब memory size या range important हो

long population = 7800000000;

अगर आप सभी C Data Types को detail में explore करना चाहते हैं, तो यह गाइड देख सकते हैं:
C Data Types – GeeksforGeeks


Declaration vs Initialization

  • Declaration (घोषणा): Compiler को बताना कि variable का type और name क्या है।
  • Initialization (आरंभिक मान देना): Variable को declare करते समय उसे कोई value assign करना

उदाहरण:

int x;            // declaration
float y = 3.14;   // declaration + initialization

Common mistake: Variable को initialize किए बिना use करना


उदाहरण: Multiple Data Types का उपयोग

#include <stdio.h>

int main() {
    int age = 20;
    float height = 5.9;
    double weight = 70.5;
    char grade = 'B';

    printf("Age: %d\n", age);
    printf("Height: %.1f\n", height);
    printf("Weight: %.2f\n", weight);
    printf("Grade: %c\n", grade);

    return 0;
}

Code Output:

Age: 20
Height: 5.9
Weight: 70.50
Grade: B

Example Explanation: Code की व्याख्या (Explanation)

  1. int age = 20;
    • एक integer variable age declare किया गया और उसे 20 value दी गई।
    • Integers हमेशा पूरे अंक (बिना दशमलव) store करते हैं।
  2. float height = 5.9;
    • एक float variable height declare किया गया जिसमें decimal value store हुई।
    • जब हमें दशमलव (decimal places) वाली value चाहिए, तब float का use करते हैं।
  3. double weight = 70.5;
    • weight नाम का double variable declare किया गया।
    • double, float जैसा ही होता है लेकिन इसमें और ज्यादा precision (सटीकता) होती है।
    • Accurate decimal values (जैसे वजन या scientific calculation) के लिए use किया जाता है।
  4. char grade = 'B';
    • एक character variable grade declare किया गया और इसमें ‘B’ store हुआ।
    • char data type सिर्फ एक character store कर सकता है।
  5. printf("Age: %d\n", age);
    • age variable की integer value print करेगा।
    • यहाँ %d integer values print करने का format specifier है।
  6. printf("Height: %.1f\n", height);
    • height की value 1 decimal place तक print होगी।
    • %.1f का मतलब है float value को 1 digit तक decimal में दिखाना।
  7. printf("Weight: %.2f\n", weight);
    • weight की value 2 decimal places तक print होगी।
    • %.2f का use तब करते हैं जब हमें exact decimal output चाहिए, जैसे पैसा (money) या weight।
  8. printf("Grade: %c\n", grade);
    • grade variable का character print होगा।
    • यहाँ %c single character print करने के लिए use होता है।
  9. return 0;
    • यह बताता है कि program successfully execute हुआ।
    • C language में यह main() function को खत्म करने का standard तरीका है।

Variables Example Summary

Variable Data Type Value Purpose (उपयोग)
age int 20 पूरे अंक (whole number) store करने के लिए
height float 5.9 दशमलव वाले numbers store करने के लिए (1–7 decimal digits तक)
weight double 70.5 ज़्यादा precision वाली decimal values store करने के लिए
grade char ‘B’ Single character store करने के लिए

ध्यान देने योग्य Common Mistakes (गलतियाँ)

  1. गलत Data Type का इस्तेमाल करना
    • अगर आप बहुत बड़ा number int में store करने की कोशिश करेंगे, तो overflow हो सकता है।
    • उदाहरण: int bigNum = 3000000000; // overflow होगा
  2. Variables को initialize न करना
    • अगर किसी variable को बिना initialize किए use करेंगे, तो unpredictable behavior (garbage values) मिलेगा।
    • उदाहरण: int x; printf("%d", x); // result random होगा
  3. Types को गलत तरीके से mix करना
    • Example: अगर आप double को int में direct assign करेंगे बिना cast किए, तो data loss होगा।
    • उदाहरण: double pi = 3.14159; int num = pi; // सिर्फ 3 assign होगा, बाकी decimal loss

sizeof Operator का उपयोग

C में sizeof() operator का use किसी data type ya variable ki memory size (bytes) जानने के लिए किया जाता है।

उदाहरण:

printf("Size of int: %zu bytes\n", sizeof(int));
printf("Size of double: %zu bytes\n", sizeof(double));

Output (system ke hisaab se alag ho sakta hai):

Size of int: 4 bytes
Size of double: 8 bytes

sizeof() ka फायदा यह है कि aapko manually याद nahi रखना पड़ता ki koi data type kitne bytes लेता है — compiler khud बता देता hai.

और पढ़ें: sizeof() Operator in C – Programiz


Variables के लिए Best Practices (अच्छे नियम)

  1. Clear aur meaningful नाम use करें int count; float temperature; ➝ नाम ऐसे होने चाहिए जिनसे variable का purpose साफ-साफ समझ आए।
  2. Declaration के समय hi initialize करें
    • हमेशा कोशिश करें ki variable को declare karte hi ek initial value दे दी जाए।
  3. Comments जोड़ें
    • Variables ke saath short comments likhne se code पढ़ने वाले ko आसानी होती है।
  4. Consistent Naming Convention Follow करें
    • जैसे camelCase (accountBalance) ya snake_case (account_balance) mein se ek format choose करें aur पूरे code mein wahi use करें।

Code Summary

#include <stdio.h>

int main() {
    int age = 25;                 // User की उम्र
    float temperature = 36.5;     // Body temperature
    double accountBalance = 1050.75; // Bank balance
    char initial = 'A';           // Name का पहला अक्षर

    printf("User data:\nAge: %d\nTemp: %.1f°C\nBalance: %.2f\nInitial: %c\n",
           age, temperature, accountBalance, initial);

    return 0;
}

Output:

User data:
Age: 25
Temp: 36.5°C
Balance: 1050.75
Initial: A

FAQs (Frequently Asked Questions) – Variables and Data Types in C in Hindi

Q1: C में Variable क्या होता है?

A: C में variable एक named memory location होता है जहाँ data store किया जाता है। Variable को use करने से पहले उसका data type और नाम declare करना जरूरी है। Example: int age = 25;

Q2: C में float और double में क्या फर्क है?

A: float लगभग 4 bytes लेता है और ~7 decimal digits तक precision देता है। वहीं double 8 bytes लेता है और ~15 decimal digits तक accurate result देता है। जब ज्यादा precision चाहिए तब double का इस्तेमाल करें।

Q3: Variables को initialize करना क्यों जरूरी है?

A: Variables को initialize करना इसलिए जरूरी है ताकि उनमें defined value रहे। अगर आप बिना initialize किए variable use करेंगे तो C garbage values (random data) return कर सकता है, जिससे program का behavior unpredictable हो जाएगा।

Q4: क्या C में एक ही line में multiple variables declare कर सकते हैं?

A: हाँ, आप ek ही line में multiple variables declare कर सकते हैं।

Example:
int x = 1, y = 2, z = 3;

लेकिन readability और clarity के लिए हर variable को अलग line पर declare करना बेहतर होता है।

Q5: C में data type का size कैसे पता करें?

A: C में किसी भी data type का size जानने के लिए sizeof() operator का use करते हैं।

Example:
printf(“%zu”, sizeof(int)); // int का size बताएगा
printf(“%zu”, sizeof(double)); // double का size बताएगा


इसे भी पढ़े –


निष्कर्ष (Conclusion)

C Programming में Variables and Data Types in C in Hindi सबसे महत्वपूर्ण concepts हैं। यदि आप सही data type चुनते हैं और variables को declaration के समय initialize करते हैं, तो आपका code सुरक्षित (safe) और कुशल (efficient) बनेगा।

अभ्यास (practice) के लिए आप अलग-अलग values बदलकर देखें और sizeof() operator का उपयोग करके memory size की जाँच करें। इससे आपको variables और data types की गहरी समझ मिलेगी।

यदि आपको यह लेख उपयोगी लगा हो तो इसे साझा करें, comment करें और अपने दोस्तों को सुझाएँ।
आप चाहते हैं कि हम अगली बार कौन सा विषय cover करें? हमें comments में ज़रूर बताइए।

Written by: Aditya (Programming Sikho)

Spread the love

Leave a Comment