What are Identifiers in C Language in Hindi
/ BCA / Programming with C and CPP
Identifiers in C Language in Hindi
What are Identifiers in C Language in Hindi
C Language में "Identifiers" एक बहुत ही मूलभूत और आवश्यक कॉन्सेप्ट है। जब हम किसी भी variable, function, array, structure, या किसी भी user-defined entity को define करते हैं, तो हम जो नाम देते हैं, उसे ही Identifier कहते हैं। सरल शब्दों में कहें तो, Identifiers वो नाम होते हैं जो हम अपनी C program में खुद से किसी चीज़ को पहचानने के लिए इस्तेमाल करते हैं।
उदाहरण के लिए यदि हम एक variable बनाते हैं जैसे int age; तो यहां पर age एक Identifier है। यह C compiler को बताता है कि आपने एक integer टाइप का variable बनाया है जिसका नाम age है।
Why are Identifiers important in C?
- Program के हर variable, function, या structure को uniquely पहचानने के लिए Identifiers जरूरी होते हैं।
- Identifiers readability बढ़ाते हैं जिससे किसी program को समझना और maintain करना आसान हो जाता है।
- Identifiers के ज़रिए हम memory locations को meaningful नाम दे सकते हैं।
Rules for naming Identifiers in C in Hindi
C Language में Identifiers को नाम देने के लिए कुछ नियम (rules) बनाए गए हैं। अगर आप इन rules को follow नहीं करेंगे, तो आपका program compile नहीं होगा और error देगा।
Basic Rules for Identifiers:
- Identifier में सिर्फ alphabets (A-Z, a-z), digits (0-9), और underscore (_) का इस्तेमाल किया जा सकता है।
- Identifier हमेशा एक alphabet (A-Z या a-z) या underscore (_) से शुरू होना चाहिए।
- Identifier कभी भी digit (0-9) से शुरू नहीं हो सकता।
- C language case-sensitive होती है, यानी
Ageऔरageदो अलग-अलग identifiers माने जाते हैं। - किसी भी C के keyword (जैसे
int,while,returnआदि) को Identifier के रूप में इस्तेमाल नहीं किया जा सकता। - Identifiers में space allowed नहीं होता।
- Identifiers की length theoretically unlimited होती है, लेकिन कुछ पुराने compilers केवल पहले 31 characters तक पहचानते हैं।
Best Practices (सुझाव):
- Identifier meaningful और descriptive होना चाहिए, जैसे
studentName,totalMarksआदि। - Shortcuts या cryptic नामों से बचें जैसे
a1,xआदि। - multi-word identifiers के लिए camelCase या underscore का प्रयोग करें।
Difference between Identifiers and Keywords in Hindi
अक्सर beginners को Keywords और Identifiers में confusion होता है, लेकिन इन दोनों में बहुत बड़ा फर्क है।
| Keywords | Identifiers |
|---|---|
| Keywords वो words होते हैं जो C language में पहले से define होते हैं। | Identifiers वो नाम होते हैं जो programmer खुद define करता है। |
| इनका अर्थ पहले से fix होता है और इन्हें बदला नहीं जा सकता। | इनका नाम programmer के अनुसार कुछ भी हो सकता है। |
| Keywords का इस्तेमाल variable या function name के रूप में नहीं किया जा सकता। | Identifiers का इस्तेमाल variables, functions, arrays, etc. को नाम देने के लिए किया जाता है। |
उदाहरण: int, while, return, if |
उदाहरण: marks, studentName, total, main |
Valid and Invalid Identifier examples in C in Hindi
अब हम Valid और Invalid identifiers के कुछ उदाहरण देखेंगे ताकि आपको समझने में आसानी हो कि कौन-से नाम मान्य (valid) होते हैं और कौन-से नहीं।
Valid Identifiers:
marks– alphabet से शुरू होता है और कोई invalid character नहीं है।_value– underscore से शुरू हो सकता है।student1– alphabet + digit combination valid होता है।total_marks– underscore allowed है।sumOfNumbers– camelCase notation valid होती है।
Invalid Identifiers:
1student– digit से शुरू नहीं हो सकता।float– यह एक C का keyword है, इसे identifier के रूप में इस्तेमाल नहीं किया जा सकता।total marks– space use नहीं किया जा सकता।student-name– dash (-) allowed नहीं है।if– यह भी एक keyword है।
Code Example:
#include <stdio.h>
int main() {
int marks = 85; // valid identifier
int _rollNo = 12; // valid identifier
int student1 = 50; // valid identifier
// int 1value = 30; // invalid identifier - digit से शुरू
// int float = 25; // invalid identifier - keyword
printf("Marks: %d\\n", marks);
printf("Roll No: %d\\n", _rollNo);
printf("Student1: %d\\n", student1);
return 0;
}
ऊपर दिए गए code में तीन valid identifiers को इस्तेमाल किया गया है। invalid identifiers को comment कर दिया गया है ताकि compiler error न दे।
कुछ और जरूरी बातें:
- अगर आप किसी identifier को सही तरीके से नहीं लिखते, तो compiler error देगा जैसे - "expected identifier before ‘number’"।
- हर programming language में identifier naming के rules थोड़े बहुत अलग हो सकते हैं, लेकिन मूल सिद्धांत लगभग समान ही होते हैं।
इसलिए एक अच्छे C programmer बनने के लिए आपको Identifiers का सही ज्ञान होना चाहिए और ऊपर बताए गए सभी नियमों और उदाहरणों को ध्यान से समझना और याद रखना चाहिए। यह concept आपकी future programming skills का आधार बनेगा।
FAQs
totalMarks, studentName आदि।
1value invalid है जबकि value1 valid है।
int, if, return आदि। जबकि Identifiers user-defined नाम होते हैं जैसे marks, age आदि।
float एक C का keyword है, इसे Identifier के रूप में इस्तेमाल नहीं किया जा सकता।
marks, _value, student1Invalid:
1student, float, total marks, student-name