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

STRING, getting a palindrome using minimum replacement

getting a palindrome using minimum replacement

Write a program using a friend function, Using a Friend Using a friend ...

Using a Friend Using a friend function is quite easy. The following example explains a friend function to access members of two classes. class Bclass;

Computer programing, pls give me answer 01110-00110 in 2''s comlpiment in d...

pls give me answer 01110-00110 in 2''s comlpiment in detail

#otto cycle, To get the efficiency of Otto cycle by C/C++.

To get the efficiency of Otto cycle by C/C++.

Explain in brief about the one-definition rule, Explain one-definition rule...

Explain one-definition rule (ODR). According to one-definition rule, C++ constructs should be identically defined in each compilation unit they are used in. As per ODR, two

AlgorithmS, Algorithm to find the value of the powers raised by integer

Algorithm to find the value of the powers raised by integer

Can a copy constructor admit an object of the similar class , Can a copy co...

Can a copy constructor admit an object of the similar class as parameter, rather than reference of the object?

Define passing by reference?, A: Method of passing arguments to a function ...

A: Method of passing arguments to a function that takes parameter of type reference.  for instance: void swap( int & x, int & y ) { int temp = x; x =

Describe what are dynamic pointers, Question: (a) Describe what are dy...

Question: (a) Describe what are dynamic pointers. Show their memory representations diagrammatically. (b) Write short notes about pointers in arrays, paying attention on

Ice_Cream Game, Do you have any solution on this activity?

Do you have any solution on this activity?

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