🟢 Beginner  ·  Lesson 06

Variables और Data Types

Variable क्या है?

एक variable memory में एक named location है जो एक value store करती है। इसे एक labeled box की तरह सोचें — आप box को एक नाम देते हैं, specify करते हैं कि इसमें किस type की चीज़ रखी जा सकती है, और फिर उसमें value डालते हैं।

Concept
// Variable = type + naam + value
int age = 20;
//  ↑    ↑    ↑
// type naam value

Declaration और Initialization

Declaration – Memory Reserve करना

C Language
int age;        // Declare — अभी value नहीं दी
float price;    // float के लिए memory reserve
char grade;     // character के लिए memory reserve

Initialization – Value देना

C Language
int age = 20;          // Declare + Initialize एक साथ
float price = 99.50f; // Float value
char grade = 'A';     // Character (single quotes!)
⚠️ Uninitialized Variables

बिना initialize किए variable use करने पर garbage value मिलती है। हमेशा variable को use करने से पहले initialize करें!

C के Data Types

1. int – Integer (पूर्ण संख्या)

Whole numbers store करता है (कोई decimal नहीं)। Size: आमतौर पर 4 bytes

C Language
int marks = 95;
int temperature = -5;   // Negative integers भी हो सकते हैं
int year = 2025;

2. float – Decimal Number (Single Precision)

Decimal numbers store करता है। Size: 4 bytes। Precision: ~6-7 decimal digits।

3. double – Decimal Number (Double Precision)

float से ज़्यादा precise। Size: 8 bytes। जब high accuracy चाहिए तो double use करें।

4. char – Single Character

एक single character store करता है। Size: 1 byte। Character को single quotes में लिखते हैं।

Sizes और Ranges

Data TypeSizeRangeFormat Specifier
char1 byte-128 से 127%c
int4 bytes-2 अरब से +2 अरब%d
float4 bytes±3.4×10³⁸ (6-7 digits)%f
double8 bytes±1.7×10³⁰⁸ (15-16 digits)%lf

Complete Programs

C Language
#include <stdio.h>
int main() {
    int    rollNo = 101;
    float  percentage = 89.5f;
    char   grade = 'A';
    double fees = 45000.75;

    printf("Roll No:     %d\n",    rollNo);
    printf("Percentage:  %.1f%%\n", percentage);
    printf("Grade:       %c\n",    grade);
    printf("Fees:        %.2lf\n", fees);
    return 0;
}
Roll No: 101 Percentage: 89.5% Grade: A Fees: 45000.75

Variable के Naming Rules

  • Letter (a-z, A-Z) या underscore (_) से शुरू होना चाहिए
  • Letters, digits (0-9), और underscores contain कर सकता है
  • Digit से शुरू नहीं हो सकता: 2age
  • C keywords use नहीं कर सकते: int, float, for
  • Case-sensitive है: age और Age अलग-अलग variables हैं

सारांश

  • Variable एक named memory location है जो value hold करती है
  • C में variable declare करते समय हमेशा data type specify करें
  • Main types: int (पूर्ण संख्या), float/double (दशमलव), char (character)
  • Format specifiers: %d (int), %f (float), %lf (double), %c (char)
  • Garbage value से बचने के लिए variables को हमेशा initialize करें
🏋️ Practice Exercise

एक C program लिखें जो आपका नाम का initial (char), age (int), CGPA (float), और total fees (double) store करे और print करे।

अक्सर पूछे जाने वाले प्रश्न (FAQ)

C में variable क्या है?
Variable एक नामित storage स्थान है जो एक value रखता है जिसे आपका program इस्तेमाल और बदल सकता है। आप इसे एक type और नाम से declare करते हैं, जैसे int age;, जो एक integer रखने को memory आरक्षित करता है जिसे आप बाद में पढ़ या update कर सकते हैं।
C में बुनियादी data types क्या हैं?
मुख्य data types हैं: पूर्ण संख्याओं के लिए int, दशमलव संख्याओं के लिए float और double, और एकल characters के लिए char। C इनके size और range समायोजित करने को short, long, signed और unsigned जैसे modifiers भी देता है।
C में float और double में क्या अंतर है?
दोनों दशमलव संख्याएँ रखते हैं, पर double ज़्यादा memory (आमतौर पर 8 bytes) इस्तेमाल करता है और float (आमतौर पर 4 bytes) से लगभग दोगुनी सटीकता रखता है। ज़्यादा सटीक दशमलव चाहिए तो double, और memory बचाना ज़्यादा मायने रखे तो float इस्तेमाल करें।
C में variable कैसे declare और initialise करते हैं?
आप type और नाम देकर declare करते हैं, और वैकल्पिक रूप से value assign करके initialise करते हैं, जैसे int count = 0;। एक line में declare और initialise करना अच्छी आदत है क्योंकि uninitialised variable अप्रत्याशित garbage value रखता है।
C में variables नाम रखने के नियम क्या हैं?
Variable नाम में letters, digits और underscores हो सकते हैं, digit से शुरू नहीं होना चाहिए, और int या return जैसा C keyword नहीं हो सकता। नाम case-sensitive हैं, तो Age और age अलग variables हैं।
← Back to C Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 लाइव कोड एडिटर

इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.