0

😟How does this work?😣

string a = "sudip"; for(long unsigned int i = 0; i < a.length(); i++){ cout<<&a.at(i)<<endl; } The output is Suprising. Output: sudip udip dip ip p Can you explain to me?

5th Aug 2021, 3:17 AM
Sudip Shrestha
Sudip Shrestha - avatar
2 Answers
+ 4
When we use "cout<<a.at(i)<<endl;" We can get s u d i p Because we are accessing the container 'a' by the index value. When we use "cout<<&a.at(i)<<endl;" We can get sudip udip dip ip p Because here we are accessing the address of a, in that just imagine, we have separate box for each letter. By accessing with address 1st time we get the value of 1, at box 's' and continuesly it outputs the followinga letters after that s 2nd time we got the value of 2, at box 'u' and continuesly it outputs the followings letter after that u Like this its done till the last box. I hope you understand. Happy Learning 🙂💐
5th Aug 2021, 6:16 AM
Sowmiyashree S
Sowmiyashree S - avatar
+ 2
5th Aug 2021, 7:26 AM
Ipang