Types of variable in C language in Hindi — यह topic beginner के लिये बहोत जरुरी है, इस लिये आज इस topic को detail से समझेंगे। अगर आप coding की दुनिया में नए हैं या फिर अपनी programming skills को मजबूत करना चाहते हैं, तो variables को समझना आपकी पहली और सबसे महत्वपूर्ण जिम्मेदारी है। Variable एक तरह का container होता है जो data को temporarily store करता है — और C language में इसके कई प्रकार होते हैं जिन्हें समझना बहुत जरूरी है।
C language को “mother of all programming languages” कहा जाता है। इसका कारण यह है कि आज की लगभग सभी modern programming languages जैसे C++, Java, Python — इन सबकी जड़ें C में ही हैं। इसलिए जब आप C में variables के प्रकार समझ लेते हैं, तो आपके लिए दूसरी भाषाएं सीखना भी बहुत आसान हो जाता है। Variables की सही समझ के बिना कोई भी program लिखना लगभग असंभव है।
इस blog post में आप सीखेंगे कि C language में variable क्या होता है, variable declare करने का सही तरीका क्या है, variables कितने प्रकार के होते हैं, हर type का scope और lifetime क्या होती है, और real examples के साथ इन्हें कैसे use किया जाता है। चाहे आप beginner हों या intermediate programmer — यह guide आपके लिए एक complete reference की तरह काम करेगी।
Table of Contents
C Language में Variable क्या होता है?
Variable एक named memory location होती है जहाँ हम program execution के दौरान data store करते हैं। सीधे शब्दों में कहें तो variable एक “डिब्बा” है जिसमें हम कोई भी value रख सकते हैं और बाद में उसे बदल भी सकते हैं।
उदाहरण के लिए:
int age = 20;
float salary = 45000.50;
char grade = ‘A’;
यहाँ age, salary, और grade — ये सब variables हैं। इनमें अलग-अलग type का data store हो रहा है।
Variable Declaration का Syntax
data_type variable_name = value;
- data_type — int, float, char, double, etc.
- variable_name — आप खुद नाम देते हैं
- value — optional initialization

Types of Variable in C Language in Hindi — पूरी जानकारी
C language में variables को मुख्यतः उनके scope, lifetime, और storage के आधार पर अलग-अलग प्रकार में बाँटा गया है। आइए हर एक प्रकार को detail में समझते हैं।
1. Local Variable (लोकल वेरिएबल)
Local variable वह variable होता है जो किसी function या block के अंदर declare किया जाता है। यह variable सिर्फ उसी function या block के अंदर ही accessible होता है, फिर चाहे वह main() हो या कोई और function.
विशेषताएं (Characteristics):
- यह function के शुरू होते ही बनता है और function खत्म होते ही destroy हो जाता है।
- इसकी lifetime सिर्फ उस function तक सीमित होती है।
- इसे function के बाहर से access नहीं किया जा सकता।
- Default value garbage होती है (automatically initialize नहीं होता)।
Example Program:
#include <stdio.h>
// Function definition
void myFunction() {
int num = 10; // This is a local variable
printf("Number: %d\n", num);
}
int main() {
int num1; // This a local variable
myFunction();
// printf("%d", num);
// This would give an ERROR because num is not accessible here
return 0;
}
कब Use करें?
जब आपको किसी specific function के लिए temporary data store करना हो, तब local variables सबसे best choice होते हैं। यह memory efficient भी होते हैं। Local Variable किसी function या block के अंदर ही बनाया जाता है, और उसका Scope वही तक होता है।
2. Global Variable (ग्लोबल वेरिएबल)
Global variable वह variable होता है जो किसी भी function के बाहर, यानी program के top पर declare किया जाता है। यह पूरे program में कहीं से भी access किया जा सकता है।
विशेषताएं:
- इसकी lifetime पूरे program execution तक होती है।
- Program के किसी भी function से इसे read और modify किया जा सकता है।
- Default value 0 (zero) होती है।
- इसे बहुत सावधानी से use करना चाहिए क्योंकि किसी भी function से इसे modify किया जा सकता है।
Example Program:
#include <stdio.h>
int count = 0; // Global variable
// Function to increase the value of count
void increment() {
count++; // Accessing the global variable here
}
// Function to display the value of count
void display() {
printf("Count: %d\n", count); // Accessing the global variable here
}
int main() {
increment();
increment();
display(); // Printing the final value
return 0;
}
Global Variable के नुकसान:
- Program बड़ा होने पर debugging मुश्किल हो जाती है।
- किसी भी function द्वारा accidentally modify होने का खतरा रहता है।
- Best practice: Global variables का use minimize करें।
3. Static Variable (स्टैटिक वेरिएबल)
Static variable एक बहुत interesting type होता है। इसे static keyword के साथ declare किया जाता है। यह local variable की तरह किसी function के अंदर होता है, लेकिन इसकी value function call के बाद भी बनी रहती है — यही इसकी खासियत है।
विशेषताएं:
- एक बार initialize होने के बाद यह program के end तक memory में रहता है।
- Default value 0 होती है।
- हर function call पर नया variable नहीं बनता — वही पुराना variable reuse होता है।
- Scope local रहता है, लेकिन lifetime global जैसी होती है।
Example Program:
#include <stdio.h>
// Function definition
void counter() {
static int count = 0; // Static variable
count++;
printf("Function called %d time(s)\n", count);
}
int main() {
counter(); // First function call
counter(); // Second function call
counter(); // Third function call
return 0;
}
अगर count static नहीं होता, तो हर बार output “Function called 1 time(s)” ही होता।
कब Use करें?
जब आपको किसी function की state को याद रखना हो — जैसे कि function कितनी बार call हुआ — तब static variable बेहद useful होता है।
4. Automatic Variable (ऑटोमैटिक वेरिएबल)
C language में by default सभी local variables automatic होते हैं। इन्हें auto keyword के साथ declare किया जाता है, लेकिन यह keyword लिखना जरूरी नहीं होता।
Example Program:
#include <stdio.h>
int main() {
auto int x = 5; // The auto keyword is optional
int y = 10; // This is also automatically an auto variable
// Printing the values of x and y
printf("%d %d\n", x, y);
return 0;
}
Modern C programming में auto keyword practically use नहीं होता क्योंकि सभी local variables default रूप से automatic ही होते हैं।
5. External Variable (एक्सटर्नल वेरिएबल)
जब आपका program multiple files में divided हो और आप एक file में declare किए गए variable को दूसरी file में use करना चाहते हों, तो extern keyword का use होता है।
विशेषताएं:
- यह किसी दूसरी file में declare किए गए global variable को current file में accessible बनाता है।
- Memory allocation नहीं होती — सिर्फ reference दिया जाता है।
- Large projects में बहुत useful होता है।
Example Program:
file1.c:
int globalVar = 100; // Declaration और Definition
file2.c:
#include <stdio.h>
extern int globalVar; // सिर्फ Declaration — definition नहीं
int main() {
printf("Global Variable: %d\n", globalVar); // Output: 100
return 0;
}
6. Register Variable (रजिस्टर वेरिएबल)
Register variable वह variable होता है जिसे CPU के register में store करने की request की जाती है — RAM में नहीं। यह execution को faster बनाता है।
विशेषताएं:
- register keyword से declare किया जाता है।
- यह compiler पर depend करता है — compiler request को accept या reject कर सकता है।
- इसका address (&) नहीं लिया जा सकता।
- Loop counters जैसे frequently accessed variables के लिए best।
Example Program:
#include <stdio.h>
int main() {
register int i; // Register variable
// Loop from 0 to 9
for(i = 0; i < 10; i++) {
printf("%d ", i);
}
return 0;
}
Note: Modern compilers खुद ही optimization करते हैं, इसलिए आजकल register keyword कम use होता है। लेकिन competitive exams और interviews के लिए यह जानना जरूरी है।
| Variable Type | Scope | Lifetime | Default Value | Keyword |
|---|---|---|---|---|
| Local | Function/Block | Function duration | Garbage | — |
| Global | Entire program | Entire program | 0 | — |
| Static | Function/Block | Entire program | 0 | static |
| Automatic | Function/Block | Function duration | Garbage | auto |
| External | Multiple files | Entire program | 0 | extern |
| Register | Function/Block | Function duration | Garbage | register |
C Language में Variable Naming Rules (नामकरण के नियम)
Types of variable in C language in Hindi को समझने के साथ-साथ यह भी जानना जरूरी है कि variables का नाम कैसे रखें:
- Variable name में alphabets (a-z, A-Z), digits (0-9), और underscore (_) ही use हो सकते हैं।
- नाम हमेशा letter या underscore से शुरू होना चाहिए — digit से नहीं।
- C language case-sensitive है — Age और age दो अलग variables हैं।
- Reserved keywords (जैसे int, float, if, for) को variable name नहीं बनाया जा सकता।
- Variable name में spaces नहीं होने चाहिए।
Valid Variable Names:
age, _count, salary2024, total_marks, firstName
Invalid Variable Names:
2age (digit से शुरू), my age (space है), int (reserved keyword), first-name (hyphen है)
Storage Classes और Variables का संबंध
C language में हर variable की एक storage class होती है जो ऊपर अभी आपने पढ़ा। जो यह तय करती है:
- Storage Location — Memory (RAM) या CPU Register
- Default Value — 0 या Garbage
- Scope — कहाँ accessible है
- Lifetime — कब तक memory में रहेगा
C में 4 Storage Classes होती हैं: auto, register, static, extern — और ये सभी directly variable types से related हैं।
Common Mistakes जो Beginners करते हैं
Programming सीखते समय beginners अक्सर ये गलतियाँ करते हैं:
- Local variable को initialize किए बिना use करना — इससे garbage value मिलती है और unexpected results आते हैं।
- Global variables का अत्यधिक use — यह code को messy और debug करने में मुश्किल बना देता है।
- Variable के scope को ignore करना — एक function में declare किए variable को दूसरे function में use करने की कोशिश करना।
- Same name के variables का confusion — Local और global दोनों में same name होने पर local variable priority लेता है।
Local और Global Variable का Priority Rule Example:
#include <stdio.h>
int x = 50; // Global variable
int main() {
int x = 10; // Local variable with the same name
// The local variable gets higher priority
printf("%d\n", x);
return 0;
}
Practical Project — Variables का Real Use
चलिये हम एक student grade calculator बनाते हैं। जिसमे आप types of variable in C language का practical use देखेंगे:
#include <stdio.h>
// Global variable
// This variable keeps track of the total number of students
int totalStudents = 0;
// Function to calculate and display grade
void calculateGrade(float marks) {
// Static variable
// Its value remains saved between function calls
static int studentCount = 0;
// Local variable
// Used to store the grade of the current student
char grade;
// Increasing counters
studentCount++;
totalStudents++;
// Checking marks and assigning grade
if(marks >= 90) {
grade = 'A';
}
else if(marks >= 75) {
grade = 'B';
}
else if(marks >= 60) {
grade = 'C';
}
else {
grade = 'F';
}
// Displaying student information
printf("Student %d\n", studentCount);
printf("Marks : %.1f\n", marks);
printf("Grade : %c\n\n", grade);
}
int main() {
// Student marks
float student1Marks = 92.5;
float student2Marks = 78.0;
float student3Marks = 55.5;
// Calling the function for each student
calculateGrade(student1Marks);
calculateGrade(student2Marks);
calculateGrade(student3Marks);
// Displaying total number of students
printf("Total Students = %d\n", totalStudents);
return 0;
}
निष्कर्ष (Conclusion)
तो दोस्तों, इस complete guide में हमने types of variable in C language in Hindi में बिल्कुल शुरुआत से लेकर advance level तक समझा। हमने देखा कि C language में variables सिर्फ data store करने का तरीका नहीं हैं — बल्कि यह program की memory management, performance, और structure की नींव होते हैं।
आइए एक बार briefly recap करें जो आपने आज सीखा:
- Local Variable — function के अंदर, सीमित scope, temporary lifetime
- Global Variable — पूरे program में accessible, पर सावधानी से use करें
- Static Variable — function calls के बीच value याद रखता है
- Automatic Variable — default local variable, auto keyword optional
- External Variable — multiple files में variable share करने के लिए
- Register Variable — fast execution के लिए CPU register में store
अगर आप C language में variables को deeply समझ चुके हैं, तो समझिए आपने programming की सबसे मजबूत foundation रख दी है। यही concepts आगे चलकर C++, Java, और Python सीखते वक्त भी काम आएंगे।
एक important बात याद रखें — अच्छा programmer वही होता है जो सही जगह पर सही type का variable use करे। Global variables का अत्यधिक use avoid करें, static variables को समझदारी से use करें, और हमेशा variable को initialize करके चलें।
क्या यह article आपके लिए helpful रहा? नीचे comment करके जरूर बताएं। अगर कोई doubt है या कोई topic और detail में समझना है, तो बेझिझक पूछें। इस post को अपने दोस्तों के साथ share करें जो C language सीख रहे हैं — क्योंकि knowledge बाँटने से बढ़ता है!
