fork download
  1. int main()
  2. {
  3. int * p; // p is a pointer to int.
  4. const int* q; // q is a pointer to const int.
  5. int const* r; // r is a pointer to const int.
  6. int * const s = nullptr; // s is a const pointer to int
  7.  
  8. int obj ;
  9. int & t = obj ; // t is a reference to int
  10. const int & u = obj ; // u is a reference to const int
  11. int const& v = obj ; // v is a reference to const int
  12. int & const w = obj ; // illegal
  13. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:12:14: error: ‘const’ qualifiers cannot be applied to ‘int&’
  int & const w = obj ; // illegal
              ^
prog.cpp:3:8: warning: unused variable ‘p’ [-Wunused-variable]
  int * p;     // p is a pointer to int. 
        ^
prog.cpp:4:13: warning: unused variable ‘q’ [-Wunused-variable]
  const int* q;    // q is a pointer to const int.
             ^
prog.cpp:5:13: warning: unused variable ‘r’ [-Wunused-variable]
  int const* r;    // r is a pointer to const int.
             ^
prog.cpp:6:14: warning: unused variable ‘s’ [-Wunused-variable]
  int * const s = nullptr; // s is a const pointer to int
              ^
prog.cpp:9:8: warning: unused variable ‘t’ [-Wunused-variable]
  int & t = obj ;   // t is a reference to int
        ^
prog.cpp:10:14: warning: unused variable ‘u’ [-Wunused-variable]
  const int & u = obj ; // u is a reference to const int 
              ^
prog.cpp:11:13: warning: unused variable ‘v’ [-Wunused-variable]
  int const& v = obj ;    // v is a reference to const int
             ^
prog.cpp:12:14: warning: unused variable ‘w’ [-Wunused-variable]
  int & const w = obj ; // illegal
              ^
stdout
Standard output is empty