Identifiers in C Language
What is an Identifier in C?
An identifier is a name given by the programmer to identify various elements of a C program. Identifiers are used to name variables, functions, arrays, pointers, structures, unions, enumerations, and other program elements. For example, total, main, student and calculateSum are identifiers.
C language is case-sensitive, which means that uppercase and lowercase letters are treated differently. Therefore, total, Total and TOTAL are three different identifiers.
C भाषा में Identifier (आइडेंटिफायर) प्रोग्रामर द्वारा प्रोग्राम के विभिन्न अवयवों की पहचान करने के लिए दिया गया नाम होता है। आइडेंटिफायर का उपयोग Variables, Functions, Arrays, Pointers, Structures, Unions, Enumerations तथा अन्य प्रोग्राम अवयवों के नाम रखने के लिए किया जाता है। उदाहरण के लिए, total, main, student और calculateSum आइडेंटिफायर हैं।
C लैंग्वेज एक Case-Sensitive भाषा है, जिसका अर्थ है कि इसमें बड़े और छोटे अक्षरों को अलग-अलग माना जाता है। इसलिए total, Total और TOTAL तीन अलग-अलग आइडेंटिफायर हैं।
Rules for Naming Identifiers in C
The following rules must be followed while creating identifiers in C language:
An identifier must begin with an English alphabet (
A–Zora–z) or an underscore (_). It cannot begin with a digit.An identifier can contain letters, digits and underscores only.
Blank spaces and special characters such as
@,#,%,:,-and.are not allowed in an identifier.A C keyword cannot be used as an identifier.
Identifiers are case-sensitive. For example,
marks,MarksandMARKSare different identifiers.There is no general eight-character limit for identifiers in modern C. However, the compiler and C standard impose certain implementation limits.
Meaningful names should be used to make programs easier to understand. This is a good programming practice.
C लैंग्वेज में आइडेंटिफायर का नाम बनाते समय निम्नलिखित नियमों का पालन करना चाहिए:
आइडेंटिफायर का पहला अक्षर English Alphabet (
A–Zयाa–z) या Underscore (_) होना चाहिए। इसकी शुरुआत किसी अंक से नहीं हो सकती।आइडेंटिफायर में केवल अक्षरों, अंकों और अंडरस्कोर का उपयोग किया जा सकता है।
आइडेंटिफायर में Blank Space तथा
@,#,%,:,-और.जैसे विशेष चिन्हों का उपयोग नहीं किया जा सकता।C लैंग्वेज के किसी भी Keyword को आइडेंटिफायर के रूप में उपयोग नहीं किया जा सकता।
आइडेंटिफायर Case-Sensitive होते हैं। उदाहरण के लिए,
marks,MarksऔरMARKSअलग-अलग आइडेंटिफायर हैं।आधुनिक C लैंग्वेज में आइडेंटिफायर के लिए आठ अक्षरों की कोई सामान्य सीमा नहीं है। हालांकि, Compiler और C Standard के अनुसार कुछ सीमाएं निर्धारित होती हैं।
प्रोग्राम को आसानी से समझने योग्य बनाने के लिए Meaningful Names का उपयोग करना चाहिए। यह एक अच्छी Programming Practice है।
Examples of Identifiers in C
1. Valid Identifiers (उचित आइडेंटिफायर)
The following are valid identifiers in C language:
int number;float a123;int simple_interest;int student1;float totalMarks;int _count;
उपरोक्त सभी आइडेंटिफायर उचित हैं क्योंकि ये C लैंग्वेज के Naming Rules का पालन करते हैं।
Although _count is syntactically valid in this example, identifiers beginning with an underscore are reserved in certain contexts by the C standard. Beginners should preferably use names that begin with a letter.
हालांकि _count इस उदाहरण में Syntax के अनुसार सही है, लेकिन C Standard के अनुसार अंडरस्कोर से शुरू होने वाले कुछ नाम Reserved होते हैं। इसलिए शुरुआती प्रोग्रामर्स को ऐसे नामों का उपयोग करना चाहिए जिनकी शुरुआत किसी अक्षर से होती है।
2. Invalid Identifiers (अनुचित आइडेंटिफायर)
The following are invalid identifiers in C language:
float :x;int for;int max marks;float 7g;int total-marks;
Explanation:
:xis invalid because it contains a special character (:).foris invalid because it is a C keyword.max marksis invalid because it contains a blank space.7gis invalid because an identifier cannot begin with a digit.total-marksis invalid because a hyphen (-) is not allowed in an identifier.
व्याख्या:
:xअनुचित है क्योंकि इसमें Special Character (:) का उपयोग किया गया है।forअनुचित है क्योंकि यह C लैंग्वेज का Keyword है।max marksअनुचित है क्योंकि इसमें Blank Space है।7gअनुचित है क्योंकि किसी आइडेंटिफायर की शुरुआत अंक से नहीं हो सकती।total-marksअनुचित है क्योंकि आइडेंटिफायर में Hyphen (-) का उपयोग नहीं किया जा सकता।
Example Program Using Identifiers in C
The following C program demonstrates the use of identifiers as variable and function names.
#include <stdio.h>int calculateSum(int a, int b){int total;total = a + b;return total;}int main(void){int num1 = 10;int num2 = 20;int result;result = calculateSum(num1, num2);printf("Sum = %d\\n", result);return 0;}
Output:
Sum = 30In this program, calculateSum, main, a, b, total, num1, num2 and result are identifiers. They are used to identify the function, its parameters and variables.
इस प्रोग्राम में calculateSum, main, a, b, total, num1, num2 और result आइडेंटिफायर हैं। इनका उपयोग Function, उसके Parameters तथा Variables की पहचान करने के लिए किया गया है।
Important Points About Identifiers
Every variable name is an identifier, but every identifier is not a variable name.
Keywords cannot be used as identifiers.
Identifiers are case-sensitive.
Identifiers should have meaningful names.
An identifier must follow the naming rules of C language.
प्रत्येक Variable का नाम एक आइडेंटिफायर होता है, लेकिन प्रत्येक आइडेंटिफायर Variable का नाम नहीं होता।
Keywords का उपयोग आइडेंटिफायर के रूप में नहीं किया जा सकता।
आइडेंटिफायर Case-Sensitive होते हैं।
आइडेंटिफायर के नाम Meaningful होने चाहिए।
प्रत्येक आइडेंटिफायर को C लैंग्वेज के Naming Rules का पालन करना चाहिए।
Comments
Post a Comment