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

Integration, Write a program to find the area under the curve y = f(x) betw...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

Basic concepts, what is the diffeerence between c and c++

what is the diffeerence between c and c++

VS Project, Hi, I want to get rtsp source for windows

Hi, I want to get rtsp source for windows

What is memory allocation, What is memory allocation? Memory Allocation...

What is memory allocation? Memory Allocation : It is the method of allocating memory storage to program in such that the program can be run.

Is probable to encompass virtual constructor? if yes, Is it probable to enc...

Is it probable to encompass Virtual Constructor? If yes, how? If not, Why?

Theory, recursive sub programs

recursive sub programs

Mobile problem, program that decodes sending smuggler''s string

program that decodes sending smuggler''s string

Error handling and constructor, Provide me the answer, Can a constructor th...

Provide me the answer, Can a constructor throws an exception? How to handle the error when the constructor fails?

Palindrome, Problem : Change to palindrome A palindrome is a string that r...

Problem : Change to palindrome 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 ta

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