Identifiers, literals, Keywords

Identifiers वे नाम हैं जो आप गढ़ते हैं (4 सख्त नियमों के साथ), keywords वे 32 नाम हैं जो C ने अपने लिए reserve कर रखे हैं, और literals वे कच्ची fixed values हैं जैसे 78, 3.14 और 'A'।

9 min read · 9 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

नामकरण संस्कार

आपके marks program में अब डिब्बे हैं, और डिब्बों को नाम चाहिए। तो आप कुछ आज़माते हैं:

total_marks... मंज़ूर। 2nd_test... नामंज़ूर। my-marks... नामंज़ूर। int... सख़्ती से नामंज़ूर।

Compiler का mood खराब नहीं है; वह नामों का एक क़ानून लागू कर रहा है जिसमें ठीक 4 नियम हैं, और साथ में शब्दों की एक छोटी list जो C ने अपने लिए रख ली है। यह क़ानून एक बार सीख लीजिए, फिर "इनमें से valid identifier कौन सा है?" paper का सबसे आसान one-marker बन जाता है।

Theory

सख्त school में बच्चे का नाम

Variable का नाम रखना किसी बहुत सख्त school में admission के लिए बच्चे का नाम रखने जैसा है। Form में सिर्फ कुछ ही characters चलते हैं (hyphen नहीं, space नहीं), नाम किसी अंक से शुरू नहीं हो सकता, और वह कोई ऐसा नाम नहीं हो सकता जो staff के लिए reserved है, आप बच्चे का नाम "Principal" नहीं रख सकते। आपके गढ़े नाम identifiers हैं; staff के reserved नाम keywords।

Theory

तीनों शब्द, ठीक-ठीक

  • Identifier: वह नाम जो आप variable, function या array के लिए गढ़ते हैं: marks, total_marks, computeGrade।
  • Keyword: वह शब्द जो C ने fixed मतलब के साथ reserve कर रखा है: int, if, else, while, for, return, char, float, void... (classic C में 32, सब lowercase)। नाम के तौर पर कभी नहीं मिलते।
  • Literal: code में सीधे लिखी fixed value: 78 (integer), 3.14 (floating), 'A' (character, single quotes), "Riya" (string, double quotes)।

एक ही line में तीनों: int marks = 78; keyword, identifier, literal।

At a glance

Identifier के 4 नियम

नियमLegalIllegal
सिर्फ letters, digits, underscoretotal_marksmy-marks (hyphen)
अंक से शुरुआत नहींtest22nd_test
Keyword नहीं हो सकताsum_intint, while
Case-sensitive: case बदला तो नाम बदलाmarks और Marks (2 डिब्बे)marks की जगह Marks लिखना (चुपचाप बग)

Quiz

इनमें से VALID C identifier कौन सा है?

  1. _total2
  2. 2total
  3. total-2
  4. return
Show the answer

_total2

Identifiers में underscore को letter जितना ही दर्जा मिला है, इसलिए उससे शुरुआत legal है: _total2 चारों नियम पास करता है। 2total अंक से शुरू होता है, total-2 में hyphen घुसा है (C उसे total minus 2 पढ़ता है), और return keyword है। 4 options वाला यह pattern हर C paper का fixture है।

Think first

Case की जाल

आपका program int marks = 78; declare करता है और बाद में Marks print करने चलता है। पहले सोचिए: वही डिब्बा या अलग? Compiler क्या कहेगा?

Show the answer

अलग। C case-sensitive है, इसलिए marks और Marks 2 बिना रिश्ते के identifiers हैं, और चूँकि Marks कभी declare ही नहीं हुआ, compiler "undeclared identifier" कहकर रुक जाता है। इसीलिए Int और INT keywords नहीं हैं, सिर्फ lowercase int है। एक naming style चुनिए (lowercase, underscores) और cases को कभी लापरवाही से मत मिलाइए।

Watch out

Marks कहाँ कटते हैं

String के लिए 'Riya' या character के लिए "A" लिखना: single quotes = एक character, double quotes = string, और exams यह फ़र्क़ सीधे पूछते हैं। int = 5; आज़माना या variable का नाम for रखना: keywords को छूना मना है। और table वाला चालाक नियम याद रखिए: identifier underscore से शुरू हो सकता है, students अक्सर उसे illegal ठहराकर mark गँवा देते हैं।

Theory

Professional नामकरण, बिना किसी खर्च के

क़ानून कहता है x legal है; समझदारी कहती है total_marks बेहतर है। 6 महीने बाद अपना ही code पढ़ने वाला अजनबी आप ही होंगे। डिब्बे का नाम वही रखिए जो उसमें रखा है (pass_marks, pm नहीं), फिर marks program कहानी की तरह पढ़ा जाएगा। अगला lesson तय करेगा कि हर डिब्बे का TYPE क्या है: पूरा number, decimal, या एक character।

Summary

Key takeaways

  • Identifiers: आपके गढ़े नाम; सिर्फ letters, digits, underscore; पहले अंक नहीं; keywords नहीं।
  • C case-sensitive है: marks, Marks और MARKS 3 अलग नाम हैं।
  • Keywords: 32 reserved lowercase शब्द (int, if, while, return...), नाम के तौर पर कभी नहीं।
  • Literals: code में कच्ची values: 78, 3.14, 'A' (single quotes), "Riya" (double quotes)।
  • int marks = 78; एक ही line में keyword + identifier + literal है।
  • याद रखने का hook: आपके गढ़े नाम, C का reserved staff, और कच्ची values।

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Introduction to C language

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati

Identifiers, literals, Keywords · Computer Programming and Programming Methodology (CPPM) · Gri-Learn