Newby Coder header banner

Identifier

What are identifiers in Programming

Identifiers are names assigned to entities such as values, objects, functions etc , which can be used to identify them

They are created to give a unique name to an entity to identify it during the execution of the program

Variables are also identifiers

Identifiers must be unique for a given scope

x = 10
def inc(y):
    x = y + 1
    return x 

In the above Python example, there are two identifiers with the name x(which are variables), one of which is inside the function inc()

Although the variable x can be accessed inside the function with global keyword

The scope of identifier x inside inc() function, begins when it is declared and ends when the execution of the function completes

The scope of the outer variable is till the program runs

Above example can be written in java as

int x = 20;
static void inc(int y) {
    x = y + 1;
    return x;
}

Rules of naming an identifier

Similar to following rules are followed in some programming languages