#includeusing namespace std; int main() { int x = 5; //local variable cout << x << endl; { int y = 10; //local variable within a nested scope cout << y << endl; } //cout << y << endl; //error: y is not defined in this scope return 0; }
#includeIn this code, function `inner` is defined within the scope of function `outer`. `inner` can only be accessed within `outer` or by functions called from `outer`. The code calls `inner` within `outer`, but attempting to call `inner` from `main` will result in an error. The package library used in these examples is the standard C++ library.using namespace std; void outer() { void inner(); //local function within the outer function cout << "outer function" << endl; inner(); //calling the inner function within the outer function } int main() { outer(); //inner(); //error: inner is not defined in this scope return 0; } void outer::inner() { cout << "inner function" << endl; }