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:
Valid and invalid identifiers in C language:
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($)
- 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
- #include <stdio.h>
- #define $pi 3.14 // pi is an identifer
- void _calc_area(int radius) { // calc_area and radius are identifiers
- printf("Area of circle: %f\n", $pi * radius * radius);
- return;
- }
- int main() {
- int $, _, radius; // $, _, radius are identifiers
- _ = 5;
- $ = 10;
- radius = 10;
- printf("Value of _: %d\n", _);
- printf("Value of $: %d\n", $);
- _calc_area(radius); // calc_area & radius are identifiers
- return 0;
- }
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
Post a Comment