1

I am unable to understand how a variable defined in an outer scope can be redefined in an inner scope.

Here is my sample code. The code compiles successfully.

#include<iostream>
#include<map>
using namespace std ;

#define ll long long int

int main(int argc, char const *argv[])
{
    ll t;
    cin>>t;
    while(t--)
    {
        map<ll,ll> mp;
        map<ll,ll>::iterator t=mp.end();
    }
    return 0;
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770

1 Answers1

0

It's not the same variables. C++ use the variable that defined in the scope first before globals variable in the same name. So in this example, you have two variables in the loop: long long t global and t map.

jacob galam
  • 781
  • 9
  • 21