Identifiers, literals, Keywords

Identifiers are the names YOU invent (following four strict rules), keywords are the 32 names C reserved for itself, and literals are the raw fixed values like 78, 3.14 and 'A'.

9 min read · 9 cards · 2 checks

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


Theory

The naming ceremony

Your marks program now has boxes, and boxes need names. So you try a few:

total_marks... accepted. 2nd_test... rejected. my-marks... rejected. int... firmly rejected.

The compiler is not moody; it is enforcing a naming law with exactly four rules, plus a small list of words C keeps for itself. Learn the law once and "which of these is a valid identifier?" becomes the easiest one-marker on the paper.

Theory

Naming a child in a strict school

Naming a variable is like naming a child for admission in a very strict school. The form allows only certain characters (no hyphens, no spaces), the name cannot begin with a digit, and it cannot be a name already reserved for staff, you cannot name your child "Principal". Your inventions are identifiers; the reserved staff names are keywords.

Theory

The three terms, formally

  • Identifier: a name YOU invent for a variable, function, or array: marks, total_marks, computeGrade.
  • Keyword: a word C reserves with fixed meaning: int, if, else, while, for, return, char, float, void... (32 in classic C, all lowercase). Never available as names.
  • Literal: a fixed value written directly in code: 78 (integer), 3.14 (floating), 'A' (character, single quotes), "Riya" (string, double quotes).

One line of code uses all three: int marks = 78; keyword, identifier, literal.

At a glance

The four identifier rules

RuleLegalIllegal
Only letters, digits, underscoretotal_marksmy-marks (hyphen)
Cannot start with a digittest22nd_test
Cannot be a keywordsum_intint, while
Case-sensitive: names differ by casemarks and Marks (two boxes)Writing Marks when you meant marks (silent bug)

Quiz

Which of these is a VALID C identifier?

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

_total2

An underscore is a letter's equal in identifiers, so starting with one is legal: _total2 passes all four rules. 2total starts with a digit, total-2 smuggles in a hyphen (C reads it as total minus 2), and return is a keyword. This four-option pattern is a fixture of every C paper.

Think first

The case trap

Your program declares int marks = 78; and later prints Marks. Think first: same box or different? What will the compiler say?

Show the answer

Different. C is case-sensitive, so marks and Marks are two unrelated identifiers, and since Marks was never declared, the compiler stops with "undeclared identifier". This is also why Int and INT are not keywords, only lowercase int is. Pick one naming style (lowercase, underscores) and never mix cases casually.

Watch out

Where marks leak

Writing 'Riya' for a string or "A" for a character: single quotes = one character, double quotes = string, and exams test the difference directly. Trying int = 5; or naming a variable for: keywords are untouchable. And remember the table's sneaky one: an identifier CAN start with an underscore, students often mark that illegal and lose the mark.

Theory

Professional naming, free of cost

The law says x is legal; wisdom says total_marks is better. Six months later, YOU are the stranger reading your own code. Name boxes for what they hold (pass_marks, not pm), and the marks program will read like a story. Next lesson decides what TYPE each box is: whole number, decimal, or a single character.

Summary

Key takeaways

  • Identifiers: names you invent; letters, digits, underscore only; no digit first; no keywords.
  • C is case-sensitive: marks, Marks and MARKS are three different names.
  • Keywords: 32 reserved lowercase words (int, if, while, return...), never usable as names.
  • Literals: raw values in code: 78, 3.14, 'A' (single quotes), "Riya" (double quotes).
  • int marks = 78; is keyword + identifier + literal in one line.
  • Memory hook: your inventions, C's reserved staff, and the raw 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