C Identifiers


 

In C programming language, identifiers are the building blocks of a program. Identifiers are unique names that are assigned to variables, structs, functions, and other entities. They are used to uniquely identify the entity within the program. In the below example “section” is an identifier assigned to the string type value.

 

Rules to Name an Identifier in C

  1. An identifier can include letters (a-z or A-Z), and digits (0-9).
  1. An identifier cannot include special characters except the ‘_’ underscore. 
  1. Spaces are not allowed while naming an identifier.
  1. An identifier can only begin with an underscore or letters.
  1. We cannot name identifiers the same as keywords because they are reserved words to perform a specific task. For example, printf, scanf, int, char, struct, etc. If we use a keyword’s name as an identifier the compiler will throw an error.
  1. The identifier must be unique in its namespace.
  1. C language is case-sensitive so, ‘name’ and ‘NAME’ are different identifiers.


Difference between Identifiers and Variables in C

Identifiers are used for the naming of variables, functions, and arrays. It is a string of alphanumeric characters that begins with an alphabet, or an underscore ( _ ) that are used for variables, functions, arrays, structures, unions, and so on. It is also known as the user-defined word. Identifier names must differ in spelling and case from any keywords. We cannot use keywords as identifiers; they are reserved for special use. Once an identifier is declared, we can use the identifier anywhere in the program to refer to the associated value

A variable is a name that points to a memory location. It is the basic unit of storage in a program. The value of a variable can be changed during program execution. All the operations are done on the variable effects that memory location. In C, all the variables must be declared before use and in C++ we can declare anywhere in the program at our convenience.

Post a Comment

0 Comments