fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. string &ref = *new string("teste");
  7. //string &ref2 = nullptr;
  8. string *ptr = new string("teste");
  9. cout << ref << endl;
  10. cout << ref.length() << endl;
  11. cout << ptr->length() << endl;
  12. cout << &ref << endl;
  13. cout << ptr;
  14. }
  15.  
  16. //https://pt.stackoverflow.com/q/328683/101
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
teste
5
5
0x555eb7a3cc20
0x555eb7a3cc50