fork download
  1. #include <iostream>
  2. #include <typeinfo>
  3.  
  4. int main()
  5. {
  6. const int i = 42;
  7. auto j = i;
  8. const auto &k = i;
  9. auto *p = &i;
  10. const auto j2 = i, &k2 = i;
  11.  
  12. // print i means int, and PKi means pointer to const int.
  13. std::cout << "j is " << typeid(j).name()
  14. << "\nk is " << typeid(k).name()
  15. << "\np is " << typeid(p).name()
  16. << "\nj2 is " << typeid(j2).name()
  17. << "\nk2 is " << typeid(k2).name()
  18. << std::endl;
  19. ++j;
  20. ++*p;
  21. ++k;
  22. ++j2;
  23. ++k2;
  24. return 0;
  25. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:20:6: error: increment of read-only location ‘* p’
   ++*p;
      ^
prog.cpp:21:5: error: increment of read-only reference ‘k’
   ++k;
     ^
prog.cpp:22:5: error: increment of read-only variable ‘j2’
   ++j2;
     ^
prog.cpp:23:5: error: increment of read-only reference ‘k2’
   ++k2;
     ^
stdout
Standard output is empty