0

Recently I've been playing with c++ and noticed that this code:

#include <iostream>
#include <string>

int main()
{
    std::string word = "hello there";
    std::cout << &word[2] << '\n';
}

prints suffix of variable word that is: "llo there".

Why is this happening? Shouldn't it return address of the third character? I also noticed that this line gives the same result:

std::cout << &*(word.begin()+2) << '\n';

Could someone explain it to me? Thank in advance

Whistleroosh
  • 87
  • 1
  • 6

0 Answers0