What are identifiers in c?

What are identifiers in c?

An identifier is a set of characters used to name variables, functions, macros and enums.

Valid characters in C language identifiers:
  • Alpha characters[a-z][A-Z]
  • Decimal numbers[0-9]
  • Underscore (_)
  • Dollar symbol($)


Valid and invalid identifiers in C language:

  • Numeric character should not be used as the first character of identifer.  Space is not allowed in the name of the identifier.  Below are some of the invalid identifier.
  • Example:
  • 9num, 1val, #val


Example of identifiers in C 


  1. #include <stdio.h>
  2. #define $pi 3.14  // pi is an identifer
  3. void _calc_area(int radius) { // calc_area and radius are identifiers
  4.       printf("Area of circle: %f\n", $pi * radius * radius);
  5.       return;
  6. }
  7.  
  8. int main() {
  9.       int $, _, radius; // $, _, radius are identifiers
  10.       _ = 5;
  11.       $ = 10;
  12.       radius = 10;
  13.       printf("Value of _: %d\n", _);
  14.       printf("Value of $: %d\n", $);
  15.       _calc_area(radius);  // calc_area & radius are identifiers
  16.       return 0;
  17. }

   Output:-Value of _: 5

                           Value of $: 10
                  Area of circle: 314.000000


$, _, radius, $pi, _calc_area are the identifiers used in the above sample program                            

Comments

Popular posts from this blog

Implement Bouncing Ball Animation Using C Graphics

Walking Stickman -Using C graphics

Sine Wave - Using C Graphics