C ++ SCOPE RESOLUTION OPERATOR

Scope Resolution Operator in C++

C ++ is an OOP Language as well as Block Structured Language. In Block Structure the same Variable can be used with different values. The value of the variable is confined to the inside of a block, its value changes as the block come out.


The variable localized within the block is called a local variable. Its value is limited to the same block. If we do not declare any Variable in Block before declaring the main () outside the block, then it will be Global Variable. You can use this variable in Function, Class, Block.


C ++ SCOPE RESOLUTION OPERATOR


In the above example, there are two blocks, Variable b is declared in the first block and Variable c declared in the second block, both of them are like Variable local Variable. Cannot use Variable b in the second block and Variable C cannot be used in the first block.


Above these two blocks is another variable declared which is the Global Variable. Its value can be used in both blocks.


Global value can be used in any block with the help of Scope Resolution Operator, that is, if there are many variables of the same name that are defined in different blocks, then the scope resolution operator is always the global variable (file scope variable) Will refer to


Example:-


#include<iostream.h>

Int a; //global a with file scope

void main ()

{

int a = 15; // local a

cout <<a; // local (a=15) print

cout <<::a; // global a (=10) print

{

int a = 16;

cout <<a; // local a (=16) print

cout <<::a; // global a (=10) print

}

}


AKASH TIMES

I AM AN ENGINEER BY PROFESSION BUT BLOGGER IS MY OLD DAYS DREAM TO CREATE MY OWN SITE FOR THOSE WHO ARE CURIOUS ABOUT MY BIRTHPLACE THEN I AM COMING FROM (INDIA). THE CURRENT CITY LIVES IN NAVI MUMBAI, INDIA

Post a Comment

IF YOU HAVE ANY PROBLEM PLEASE FELL FREE TO CONTACT US BY - AKASH TIMES

PREVIOUS POST NEXT POST