The ones who are crazy enough to think they can change the world are the ones who do.
- Steve Jobs

Scope Resolution Operator In C

Scope Resolution operator tells the compiler to use global variable instead of local variable. A variable followed by scope Resolution operator must be initialized globally. Scope Resolution operator is represented by the symbol ::.

Scope Resolution Operator

Scope resolution operator program

Unfortunately, C programming doesn't support scope resolution operator. So by making using C Plus Plus with an extention .cpp to learn scope resolution operator for future use.

scoperesolution.c
#include <stdio.h> //header file section
int value();        // function declaration
int a = 7;          //variable a is declared globally
int main()
{
value();           //calling a function
return 0;
}
int value()
{
int a = 5;
printf("The value of a = %d ",a);
printf("\nThe value of a = %d ",::a);
return 0;
}
  • The value of a = 5
  • The value of a = 7

Note:

Here, the second printf tells the compiler to use global variable instead of local variable.

Report Us

We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.

Report