Loading...
Loading...
00:00:00

What Is Identifier?

In C language, an identifier is a name used to identify a variable, function, or any other user-defined item in a program. An identifier can be composed of letters (both uppercase and lowercase), digits, and underscore (_), but cannot start with a digit. Identifiers are case-sensitive, which means that the identifiers "myVar" and "myvar" are considered different. It is important to choose meaningful and descriptive identifiers to make the code more readable and easier to understand.

In C language, Idenfier is user defined name of variable or level of data type we define for variables, functions, arrays, structures, unions etc. To create a identifier we have to use combination of alphanumeric characters, identifier name starts with alphabet or an underline but not digit or any special characters and rest of the portion of identifier may be digit or any Special characters.

Special characters like ! " # % & ' ( ) * + , - . / : ; <=> ? [ \ ] ^ _ { | } ~
Whitespace characters: space, horizontal tab, vertical tab, form feed, newline.

There Are Two Types Of Identifiers

Internal Indetifiers - Internal identifier is cannot use out side of block(in external linkage). such as local variables.

External Indetifiers - External identifier is accessible outside of block(in external linkage). such as function name or global variables.

Rules For Identifier

  • The first character of an identifier should be either an alphabet or an underscore.
  • Identifier cannot starts with digit or any special characters.
  • Identifier is case sensitive, uppercase and lowercase letters are distinct.
  • We cannot use comma or space in identifier.
  • We cannot use reserved keywords as identifier.
  • The length of the identifiers should not be more than 31 characters.

How To Create Identifier?

According to above rules here is the some examples of identifiers.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char const *argv[])
{
    // valid identifiers
    int num1, num2, add;
    char a, _b, Char;
    float total_rate;
    void fun1(){};
    // invalid identifiers
    // int 2price;       // Error
    // char #_first_day; // Error
    // float max value;  // Error
    //void @function (){};  // Error
    return 0;
}