Identifiers in C

 



Identifiers in C


Identifiers in C are names given to variables, functions, structures, unions, and other entities within a C program. They serve as labels to uniquely identify these elements.


Rules for Identifiers:

  1. Case-sensitive: myVariable and myvariable are considered different identifiers.
  2. Start with a letter or underscore: Identifiers cannot start with a digit.
  3. Contain only letters, digits, and underscores: No other characters are allowed.
  4. Cannot be a keyword: Identifiers cannot be the same as reserved keywords in C (e.g., int, if, while).

Examples of Valid Identifiers:

  • variable_name
  • myFunction
  • MyStruct
  • _private_variable

Examples of Invalid Identifiers:

  • 123variable (starts with a digit)
  • my-variable (contains a hyphen)
  • int (a reserved keyword)

Best Practices for Naming Identifiers:

  • Meaningful names: Choose names that reflect the purpose of the identifier.
  • Use underscores or camelCase: Use consistent naming conventions to improve readability.
  • Avoid using reserved keywords: To prevent conflicts and improve clarity.
  • Be consistent: Use a consistent naming style throughout your code.

Common Naming Conventions:

  • CamelCase: myVariableName
  • Underscore: my_variable_name

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Ok, Go it!