Identifier in Cpp

Identifier in Cpp


What is Identifier ?

An identifier is a collection of alphanumeric characters that are used to represent variables, functions, arrays, structures, unions, labels and so on.

How to declare an Identifier ?

Syntax : 
datatype IdentifierName;
Example :
#include <iostream>
using namespace std;
int main()
{
  int she;
  float anik;
  return 0;
}

//here, int, float are datatypes.
// she and anik are identifiers.


Rules for declaration of Identifiers :

1. First character must be started with a letter or an underline not with a digit. The remaining are of an alphabet, any numeric digit or the underscore character. Including both uppercase and lowercase there are 53 characters, to represent Identifiers. The underscore( _ ) character is considered as a letter in identifiers. So There are total 63 alphanumeric characters, which are 53 alphabetic characters and 10 digits (i.e., 0-9).
2. Identifier names must be unique.
3. Blank spaces and commas are not allowed within an Identifier.
4. Keywords can't be used as identifiers.
5. There is no rule on how long an identifier can be. The major difference between C and C++ is the limit on the length of the name of the variable. ANSI C considers only the first 32 characters in a name while ANSI C++ imposes no limit on the length of the name.
6. Identifiers are case sensitive.

Example  :
#include<iostream>
using namespace std;
int main()
{
  int Anik=117,anik=56,aniK=211;
  cout << "The value of the identifiers are : \n" << Anik <<endl <<anik <<endl <<aniK;
  return 0;
}

Output :



7. Once an identifier is declared under any datatype it can't be redeclared even in its current datatype itself. It will cause error in the output.

Example  :

#include<iostream>
using namespace std;
int main()
{
  int Anik=117,anik=56,anik=211;
  cout << "The value of the identifiers are : \n" << Anik <<endl <<anik <<endl <<anik;
  return 0;
}

//The output will cause an error as anik is redeclared.

Output :