Binding Behavior
What this preview is
Binding Behavior is a easy quant interview question on language knowledge in Cpp.
- Difficulty
- Easy
- Topic
- Language Knowledge
- Discipline
- Quant development
- Language
- Cpp
- Companies
- 0
#include
using namespace std;
int x = 5;
int main() {
int x = 10;
{
int x = 15;
cout << x << endl;
}
cout << x << endl;
cout << ::x << endl;
return 0;
}
```
What this C++ variable scoping question tests
This easy question probes your understanding of name binding and variable shadowing in C++. It is a common warm-up in technical interviews to establish baseline fluency with scope rules before moving to harder problems.
The question rewards careful reading of scope boundaries and the ability to distinguish between local, block-local, and global variable declarations. You need to trace which declaration is active at each point in the code, and understand how the scope-resolution operator (::) lets you bypass shadowing to access names in outer scopes.
- Local scope and block scope in C++
- Variable shadowing and name resolution order
- The global scope-resolution operator
Related practice
Unlock full access to getcracked
Join to unlock this question, detailed solutions, and our complete library of quant finance interview prep.