View Single Post
  #3 (permalink)  
Old October 23rd, 2006, 03:57 PM
skoob1152 skoob1152 is offline
Authorized User
 
Join Date: Mar 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to skoob1152 Send a message via Yahoo to skoob1152
Default

Hi my friend here is a better answer for you:

What is the scope for this varaible(MyVariable)?
for(int i=0;i<10;i++)
{
   int MyVariable; // the scope of this variable is local because
   do something; // you only have acces to the variable inside of
} // the for statement;


On the othet hand we have global variables:

#include<stream.h>

int MyGlobalVariable = 5; //This is a global variable because is
                           //declared before the main function
int main() // this meand that you can use this
 { // variable on any part of the code
                           // including in "for" statements.
return 0;
 }

Ok! so the scope of variable depend where you declare the variable (local or global).
A variable can be either of global or local scope. A global variable is a variable declared in the main body of the source code, outside all functions, while a local variable is one declared within the body of a function or a block.







Reply With Quote