Blue Theme Orange Theme Green Theme Red Theme
 
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
Search :       Advanced Search »
Home » Blogs Home » Blog Detail

Scope and Visibility

 by Sivaraman Dhamodaran on Sep 07, 2011

What is Variable Scope and Variable Visibility.
Comments: 0 Views: 692 Printable Version 

The scope says how long the variable lives or I can say how long the value in the variable is persisted without losing its value. For example look at the function below:

 

int somefunction()

{

            int x;

            int y;

            //Some work here

            x = 15;

            y = y * y * y;

}

 

In the above function the scope of the variable x and y is inside the function. That means when the function returns the variable values x and y are lost. You may not expect the value of 15 in x in the comment shown when the same function is called next time since the value is lost at the end of the previous function call.

 

OK. Visibility is the value x is visible only inside the function. Other functions are not aware of x. If you assume the value x is declared outside the function at the top of the CPP file and there are three more functions in the same .cpp file, then variable x is visible inside all the function.

 

In the above function Scope and visibility of variable x is inside somefunction()

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
 
What do you say about this post? Post a comment here
*Title:
*Comment:
 
Comments not available.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor

 Blogger's Profile
Age: Not Available
Location:
Title: Systems Engineer
Joined: Oct 21, 2010
Education: Masters Degree
 More Blogs from this Blogger
[Video] OnClose Handler
[Video] Storing and Loading the Window and Toolbar position
Swapping Exe Process
How Exe file is Generated by VS2005 C++ Project?
What is Exe
Header files: Multiple Inclusion problem - Solution B
Header files: Multiple Inclusion problem - Solution A
Header files: Multiple Inclusion problem - Reason
Header files: Multiple Inclusion problem
Header file inclusion techniques
View all »
 Latest Blogs
[Video] OnClose Handler
[Video] Storing and Loading the Window and Toolbar position
The Euclidean Algorithm
Swapping Exe Process
How Exe file is Generated by VS2005 C++ Project?
What is Exe
Header files: Multiple Inclusion problem - Solution B
Header files: Multiple Inclusion problem - Solution A
Header files: Multiple Inclusion problem - Reason
Header files: Multiple Inclusion problem
View all »
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 
Team Foundation Server Hosting
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.