Google News
logo
CPP - Interview Questions
Can you discuss the difference between a local and global scope of a variable?
There are two types of scope in C++, local and global. A variable has a local scope when it is declared inside a code block. The variable remains active only inside the block and is not accessible outside the code block. Conversely, a variable has a global scope when it is accessible by the entire program. A global variable needs to be declared at the top of a program before all the function definitions.
Advertisement