Day#58 'C' Coding Challenge

Day#58 'C' Coding Challenge

What is linkage in C Programming language?

Linkage is basically a property which determines the scope of the variables. It determines how the variables are linked in the program. This is taken care by the linker. 

Linkage can be Internal Linkage or External Linkage.

Internal Linkage is something which links the variables to a specific section and those linked to that section cannot be accessed outside it. Example implementation is static variables

func()
{
    static int a = 0;
    ............
    ............
}

In the above code, as the variable a is local, internal linkage doesn't matter.

if there are multiple files in a program and one files has below code,

static int a = 0;
func()
{   
    ............
    ............
}

In the above case a cannot be accessed outside its' file.

External Linkage is something which links the variables across the program and can be accessed from anywhere in the program. Example implementation is variables declared with extern keyword. 

Post a Comment

0 Comments