Google News
logo
CPP - Interview Questions
What is the difference between the local and global scope of a variable and what is their order of precedence if they both are of the same name?
The local scope of a variable allows the variable to work inside a restricted block of code. For instance, if it is declared inside a function, you cannot access it from the main function without calling the function whereas the global scope of a variable allows the variable to be accessible throughout the entire program.
 
It is a well-established fact that whenever a program has a local and global variable, precedence is given to the local variable within that program.
Advertisement