c++ - Declaring a variable as global and then as local -Shadowing- -
what mean declare variable global , re-declare local this:
int = 0; int main() { int = 7; return 0; } i saw example in reference, don't understand it. please put consideration i'm beginner @ programming c++
this means in main method if use a, refer 1 declared in method, because shadows global one. access global one within main, need access via ::a. within other methods if use a, refer 1 global every method in file. scopes work this, if doesn't find variable, goes , tries find in outer scope , on global scope.
one advice avoid global variables
Comments
Post a Comment