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?
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 đđ
+ 2
Hope this can clear the doubt
https://code.sololearn.com/cLkS8qODz58R/?ref=app