.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Code Snippets >> ADO.NET >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

The Scope Resolution Operator

Posted By:Nikhil Kumar       Posted Date: April 20, 2010    Points: 10    Category: ADO.NET    URL: http://www.dotnetspark.com  

Defining Scope Resolution Operator with example

Defining the Scope Resolution Operator

Global variables are defined outside any functions and thus can eb used by all the functions defined thereafter,  However, if a global variable is declared with the same name as that of a local variable of a function. the local variable is the one in the scope when the program executes that funtction.The C++ language provides the scope resolution operator (::) to access the global variable thus overriding a local variable with same 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

Thanks  !!


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend