Identifiers in C

Identifiers in C

 Identifiers in C

Identifiers in C are the name given to the program unit such as character sets, variables, structures, function, underscore, digits, etc. They are not already defined in a programming language but used to define by the programmer.

Some basic rules to define identifiers in C

  • The first character must be an alphabet or underscore.
  • It must consist of only letters, digits, and underscore.
  • Any standard C language keyword cannot be used as an identifier name.
  • It should not contain a space.
  • It allows both uppercase and lowercase characters.

 

Valid identifiers

A,  b,  bc,  Bn,  Nirmal,  FIRST_NAME,  x_1,  _k,  _l_


Invalid identifiers

1a, 34BB, int, void, float, char, FIRST-NAME, x.1, n b

 

Let see one example

#include<stdio.h>

#include<conio.h>

void main()

{

   int a = 5;

   float B5 = 7.8;

   char FIRST_NAME = 'A';

   char _n = 'c';

   int x_1=10;

   printf("\n %d", a);

   printf("\n %f", B5);

   printf("\n %c", FIRST_NAME);

   printf("\n %c", _n);

   printf("\n %d", x_1);

   getch();

}

Output

identifiers_in_c


When we started identifiers with digits, errors will come while compiling.

Example:

#include<stdio.h>

#include<conio.h>

void main()

{

  int 1a;

      printf("%d", 1a);

   getch();

}

 

 Error message

error_message_in_c



Post a Comment

0 Comments