i want to know that what in IT iterator why is it returning address
when auto keyword is used
whereas when we use int keyword it returns value and not address
Iterators and auto keyword
@asaraf2407 hey iterators point to location of variable and return adress.The auto keyword is simply asking the compiler to deduce the type of the variable from the initialization.
Even a pre-C++0x compiler knows what the type of an (initialization) expression is, and more often than not, you can see that type in error messages.
#include
#include
using namespace std;
int main()
{
vectors;
s.push_back(11);
s.push_back(22);
s.push_back(33);
s.push_back(55);
for (int it=s.begin();it!=s.end();it++){
cout<<*it<<endl;
}
}
Line 12: error: cannot convert β__gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<int*, __gnu_norm::vector<int, std::allocator > >, __gnu_debug_def::vector<int, std::allocator > >β to βintβ in initialization
The auto keyword simply allows you to take advantage of this knowledge - if you (compiler) know the right type, just choose for me!