Skip to content

Identifiers and Key Words

Identifiers:

In C, an identifier is a name given to various program elements such as variables, functions, arrays, etc. These names are used to identify and refer to these elements throughout the program. Here are some important points about identifiers:

  1. Rules for Naming Identifiers:
    • Identifiers must begin with a letter (uppercase or lowercase) or an underscore (_).
    • Subsequent characters can be letters, digits (0-9), or underscores.
    • Identifiers are case-sensitive, meaning myVariable and MyVariable are different identifiers.
    • Identifiers cannot contain whitespace characters like spaces, tabs, etc.
  2. Examples of Identifiers:
    • Variable names: count, totalAmount, userInput.
    • Function names: calculateSum, displayMessage, getInput.
    • Array names: scores, studentNames, matrix.
  3. Best Practices for Naming Identifiers:
    • Use meaningful and descriptive names that indicate the purpose or usage of the identifier.
    • Follow a consistent naming convention across your codebase for better readability.
    • Avoid using single-letter names or overly cryptic abbreviations.

Keywords:

Keywords, also known as reserved words, are predefined words in the C language that have special meanings and functionalities. These words are reserved by the language and cannot be used as identifiers (variable names, function names, etc.). Here are some important points about keywords:

  1. Usage:
    • Keywords are used to define the syntax and structure of the C language.
    • They represent control structures, data types, modifiers, etc.
  2. Examples of Keywords:
    • Control flow: if, else, switch, case, default, while, do, for, break, continue, goto.
    • Data types: int, char, float, double, void, long, short, signed, unsigned.
    • Storage class specifiers: auto, register, static, extern.
    • Other: const, volatile, sizeof, return, typedef, enum.
  3. Restrictions:
    • Keywords cannot be used as identifiers (variable names, function names, etc.).
    • Attempting to use a keyword as an identifier will result in a syntax error.
  4. Evolution:
    • The set of keywords in C has remained largely unchanged over the years, with new standards occasionally introducing new keywords.

Understanding identifiers and keywords is fundamental to writing correct and readable C code. By following the rules for naming identifiers and being aware of reserved keywords, programmers can create maintainable and understandable codebases.