Identifiers and Keywords

In C programming, identifiers and keywords are fundamental concepts that serve distinct purposes.

Identifiers

Identifiers are names given to various program elements, such as variables, functions, arrays, and structures. They are user-defined names that allow programmers to refer to these elements conveniently.

Rules for Identifiers:

  1. Must begin with a letter (A-Z, a-z) or an underscore (_).
  2. Subsequent characters can be letters, digits (0-9), or underscores.
  3. Cannot use spaces or special characters (like @, #, $, etc.).
  4. C is case-sensitive, meaning variable, Variable, and VARIABLE are different identifiers.
  5. Identifiers should not be the same as C keywords.

Examples of Valid Identifiers:

  • myVariable
  • count_1
  • _temp

Examples of Invalid Identifiers:

  • 1stVariable (cannot start with a digit)
  • my-variable (contains a hyphen)
  • int (a keyword)

Keywords

Keywords are reserved words that have special meanings in C. They are part of the C language syntax and cannot be used as identifiers. Keywords define the structure and control the flow of the program.

Common C Keywords:

  • int: Defines an integer type.
  • float: Defines a floating-point type.
  • char: Defines a character type.
  • return: Exits a function and optionally returns a value.
  • if, else: Control flow statements for conditional execution.
  • for, while: Loop control statements for iterative execution.
  • void: Specifies that a function does not return a value.

Summary

  • Identifiers are user-defined names for program elements, following specific naming rules.
  • Keywords are reserved words that have predefined meanings in C and cannot be used as identifiers.




  • To Share this Link, Choose your plateform


Our Other Tutorials