Results 1 to 4 of 4

Thread: What does scope of variables means?

  1. #1
    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 ...

  2. #2
    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.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    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..

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    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:

    #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;
    }

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,727,200,918.01697 seconds with 17 queries