P
pembed2003
Hi all,
I am reading the book "C++ How to Program" and in the chapter where it
discuss scope rule, it says there are four scopes for a variable:
function scope
file scope
block scope
function-prototype scope
I think(might be wrong):
file scope: variables declared outside of any functions.
block scope: variables declared inside a block such as a function. For
example:
int f(int i, int j){
int k;
return 0;
}
then the variable i, j and k are all block scope, right?
function-prototype scope: The book said C ignores those. For example:
int f(int x,int y);
in this case, x and y are function-prototype scope?
function scope: This one I don't know. The book said only labels have
function scope and the 'switch' and 'goto' statements normally uses
those. For example:
int h(int i){
again:
if(i == 0)
goto again;
}
does 'again' have function scope? I am confuse. Can someone help me
out?
Also, What does static and extern use for? I know static can be used
to make the variable persist after function calls but what about
exter?
Thanks!
I am reading the book "C++ How to Program" and in the chapter where it
discuss scope rule, it says there are four scopes for a variable:
function scope
file scope
block scope
function-prototype scope
I think(might be wrong):
file scope: variables declared outside of any functions.
block scope: variables declared inside a block such as a function. For
example:
int f(int i, int j){
int k;
return 0;
}
then the variable i, j and k are all block scope, right?
function-prototype scope: The book said C ignores those. For example:
int f(int x,int y);
in this case, x and y are function-prototype scope?
function scope: This one I don't know. The book said only labels have
function scope and the 'switch' and 'goto' statements normally uses
those. For example:
int h(int i){
again:
if(i == 0)
goto again;
}
does 'again' have function scope? I am confuse. Can someone help me
out?
Also, What does static and extern use for? I know static can be used
to make the variable persist after function calls but what about
exter?
Thanks!