Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 24-11-2009
Member
 
Join Date: Jan 2009
Posts: 30
What does scope of variables means?

Hi Friends,

I have confusion regarding scope of variables. I am not aware about concept of "scope of variables". The only thing which is know is that it very important to declare scope of the variable or method for there availability in the other method. Can you explain me what does scope of variables means?

Your help will be greatly appreciated ...
Reply With Quote
  #2  
Old 24-11-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: What does scope of variables means?

Hi,

The area or part program in which variable can be accessed is called as "Scope of that variable". Basically there are two types of scope i.e "Global scope" and "Local scope".Variable declared with "Global scope" known as "global variables". "Global variables" are basically defined outside of function and by default it is accessible from any function

Following shows the valid combinations of storage class and scope:

Scope ...........................Storage class

..................................... static...........auto

local .................................Y ...............Y
global.................................Y ............... N

Last edited by Praetor : 24-11-2009 at 01:37 PM.
Reply With Quote
  #3  
Old 24-11-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: What does scope of variables means?

Scope of the variable represent the accessibility or visibility of that variables. Scope of the variable is the section of the code of the program can be use or seen it.

Basically every variable of the program has a scope of type "Global". It is very essential to control a scope of variable to a single function. There are two types variable's scope one is Global and another is Local.

I hope this information will helps you in understanding scope of variable..
Reply With Quote
  #4  
Old 24-11-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: What does scope of variables means?

Variables can have two various types of scopes. When you declare a variable outside of any method declaration, then it called as "global variable". And when you declare a variable within a method declaration, then it called as "local variable".

Refer below example:

Quote:
#include <iostream>
using namespace std;

short ::count = 0;

short counter()
{
::count ++;

cout << ::count << " ";

return 0;
}

int main()
{
short a;

for (a = 0; a < 10; a ++)
counter();

return 0;
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What does scope of variables means?"
Thread Thread Starter Forum Replies Last Post
Which has more scope MBA, IAS or CA Dharamsia Education Career and Job Discussions 3 11-04-2013 12:25 PM
what is the scope for MBA in production withnikhya@gmail.com Education Career and Job Discussions 1 30-08-2012 07:00 PM
What is the future scope of php ? Chinye Education Career and Job Discussions 11 29-03-2012 02:36 PM
How to use Variable scope in PHP? super soaker Software Development 4 21-02-2010 06:48 AM
Scope of Computer Animation NGV BalaKrishna Education Career and Job Discussions 3 16-02-2009 07:35 PM


All times are GMT +5.5. The time now is 02:40 AM.