C:scope,visibility & extent of a variable

     I'm confused about the concepts of scope,visibility and extent of a variable in C.I'M NOT ABLE TO DISTINGUISH ONE
CONCEPT FROM THE OTHER.Please help me.How are they
related with each other ?
stsatishAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

stsatishAuthor Commented:
I'm a beginner in C, I've looked up several books and none
of them have been able to help me out as far as my problem
is concerned.I hope you do.Thankyou.
0
mjswartCommented:
Scope: means the lines of the code where a variable is valid. So a global variable's scope would be a whole file while a functions variable would be only the lines of a function.
Extent: means the same as scope.
Visibility: refers to whether a variable is global or local.

The following demonstrates a local and a global variable. If this doesn't help as far as your problem is concerned, could you give more detail on your problem?

/* global variables */
int a;  /* this variable may be referenced
             anywhere in this file */

/* prototype for a function */
int otherfunction();

int main()
{
    /* local variables */
    int b=1; /* this variable may only be
                    referenced in this function */
    a = b;
    otherfunction();
}

int otherfunction()
{
    printf("%d", a); /* valid */
    printf("%d", b); /* invalid */
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stsatishAuthor Commented:
Thankyou for your help.Regarding the visibility of a variable:
                Can a local variable become invisible inside the function where it is declared?
0
Redefining Cyber Security w/ AI & Machine Learning

The implications of AI and machine learning in cyber security are massive and constantly growing, creating both efficiencies and new challenges across the board. Join our webinar on Sept. 21st to learn more about leveraging AI and machine learning to protect your business.

mjswartCommented:
Not at all,  but it can be overridden:

int myfunction()
{
    int i = 0;
   
   /* start of block (you can do this to limit scopes)*/
   {
       float i = 4.5;
       /* within this block, i is a long */
    }
    /* end of block, i is an int again. */

}


hope it h;elps
0
stsatishAuthor Commented:
Thank you.I'm baffled by the following
declaration:

  int (*x) [ ];

 Can you please clarify?
0
mjswartCommented:
sorry, It looks like a pointer to a function and I've always stayed clear of those..

Sorry I couldn't help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Hardware

From novice to tech pro — start learning today.