Notes in Hindi

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

Identifiers वे नाम होते हैं जिन्हें programmer variables, functions, arrays आदि को पहचानने के लिए इस्तेमाल करता है। ये user-defined नाम होते हैं जैसे – totalMarks, studentName आदि।
Identifiers alphabet या underscore से शुरू होने चाहिए, उनमें alphabets, digits और underscore का ही इस्तेमाल किया जा सकता है। Spaces, special characters और keywords का उपयोग नहीं किया जा सकता।
नहीं, C में कोई भी Identifier digit से शुरू नहीं हो सकता। जैसे 1value invalid है जबकि value1 valid है।
Keywords पहले से परिभाषित होते हैं और language के हिस्से होते हैं, जैसे int, if, return आदि। जबकि Identifiers user-defined नाम होते हैं जैसे marks, age आदि।
नहीं, float एक C का keyword है, इसे Identifier के रूप में इस्तेमाल नहीं किया जा सकता।
Valid: marks, _value, student1
Invalid: 1student, float, total marks, student-name

Please Give Us Feedback