Explain the scope resolution operator, C/C++ Programming

Assignment Help:

The Scope Resolution Operator( :: )

Global variables are explained outside any functions and thus can be used by all the functions defined thereafter. However, if a global variable is declared with the similar name as that of a local variable of a function , the local variable is the one in the scope when the program implements that function . The C++ language provides the scope resolution operator ( :: ) to access the global variable thus overriding a local variable with the similar name. This operator is prefixed to the name of the global variable . The following example shows its usage.

                int global = 10;

                void main()

                 {

                                int global = 20;

 

                                printf(" Just writing global prints : %d\n", global);  

printf(" Writing ::global prints : %d\n", ::global);  

 }

The output of this program will be:

 Just writing global prints : 20  

 Writing ::global prints    : 10

 

 


Related Discussions:- Explain the scope resolution operator

Minimum shelf, At a shop of marbles, packs of marbles are prepared. Packets...

At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with thes

Copy constructor and overloaded assignment operator, please provide me the ...

please provide me the assignment help. What is the difference between a copy constructor and an overloaded assignment operator?

Change to palindrome, A palindrome is a string that reads the same from bot...

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Draw pie chart in c++ program, Draw pie chart in c++ program: int main...

Draw pie chart in c++ program: int main() {                 char cmd;                   cout                 cout                 cmd = toupper(getch());

#pointers, what is the purpose of pointer ? what is the syntax? how it work...

what is the purpose of pointer ? what is the syntax? how it works?

Explain integer literal, Integer literal Integer is numbers without fra...

Integer literal Integer is numbers without fractional parts. e.g. 20       // Decimal 024      // Octal     0x14     // Hexadecimal To indicate long, unsigned,

What are the debugging methods you employ while came across , What are the ...

What are the debugging methods you employ while came across a problem? A: Debugging with tools such as: 1.      DBG, GDB ,Forte, Visual Studio. 2.      Using tusc to trace

Arrays, Write two different arrays. Store the names in it and then compare ...

Write two different arrays. Store the names in it and then compare if both the names entered by the user are the same.

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd