C - Identifiers
C - Identifiers
C - Identifiers
Identifier in C helps in identifying variables, constants, functions etc., in a C code.
C, being a high-level computer language, allows you to refer to a memory location
with a name instead of using its address in binary or hexadecimal form.
C Identifiers
Identifiers are the user-defined names given to make it easy to refer to the memory.
It is also used to define various elements in the program, such as the function, user-
defined type, labels, etc. Identifiers are thus the names that help the programmer to
use programming elements more conveniently.
Even if the programmer can use an identifier of his choice to name a variable or a
function etc., there are certain rules to be followed to form a valid identifier.
https://www.tutorialspoint.com/cprogramming/c_identifiers.htm 1/7
6/16/24, 10:59 AM C - Identifiers
As per the above rules, some examples of the valid and invalid identifiers are as
follows −
Valid C Identifiers
Invalid C Identifiers
Examples of C Identifiers
The following program shows an error −
#include <stdio.h>
int main () {
/* variable definition: */
int marks = 50;
float marks = 65.50;
printf("%d %f", marks, marks);
https://www.tutorialspoint.com/cprogramming/c_identifiers.htm 2/7
6/16/24, 10:59 AM C - Identifiers
return 0;
}
Error
Scope of C Identifiers
In C language, the scope of identifiers refers to the place where an identifier is
declared and can be used/accessed. There are two scopes of an identifier:
Global Identifiers
If an identifier has been declared outside before the declaration of any function, it is
called as an global (external) identifier.
Example
https://www.tutorialspoint.com/cprogramming/c_identifiers.htm 3/7
6/16/24, 10:59 AM C - Identifiers
#include <stdio.h>
int main() {
printf("The value of marks is %d\n", marks);
}
Output
Local Identifiers
On the other hand, an identifier inside any function is an local (internal) identifier.
Example
#include <stdio.h>
int main() {
int marks= 100; // internal identifier
Output
https://www.tutorialspoint.com/cprogramming/c_identifiers.htm 4/7
6/16/24, 10:59 AM C - Identifiers
struct student
{
int rollno;
char *name;
int m1,m2,m3;
float percent
};
struct student s1 = {1, "Raju", 50, 60, 70, 60.00};
struct student
{
int rollno;
char *name;
int m1,m2,m3;
float percent
};
typedef struct student STUDENT;
STUDENT s1 = {1, "Raju", 50, 60, 70, 60.00};
#include <stdio.h>
int main()
{
int x=0;
begin:
https://www.tutorialspoint.com/cprogramming/c_identifiers.htm 5/7
6/16/24, 10:59 AM C - Identifiers
x++;
if (x>=10)
goto end;
printf("%d\n", x);
goto begin;
end:
return 0;
}
Output
1
2
3
4
5
6
7
8
9
#include <stdio.h>
enum week{Mon=10, Tue, Wed, Thur, Fri=10, Sat=16, Sun};
int main() {
printf("The value of enum week: %d\n",Mon);
return 0;
}
Output
Thus, the identifiers are found everywhere in the C program. Choosing right
identifier for the coding element such as the variable or a function is important for
enhancing the readability and debugging and documentation of the program.
https://www.tutorialspoint.com/cprogramming/c_identifiers.htm 6/7
6/16/24, 10:59 AM C - Identifiers
https://www.tutorialspoint.com/cprogramming/c_identifiers.htm 7/7