fork download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5. //part 1
  6. //not able to compile
  7. int *b1 = 0;
  8. const int *& n1 = b1;
  9.  
  10.  
  11. //part 2
  12. //able to compile
  13. int a2 = 0;
  14. int *b2 = &a2;
  15. const int & n2 = *b2;
  16. cout << n2 << endl; // n = 0
  17. *b2 = 3;
  18. cout << n2 << endl; // n = 3
  19.  
  20. return 0;
  21. }
Compilation error #stdin compilation error #stdout 0s 3464KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:8:23: error: invalid initialization of non-const reference of type 'const int*&' from an rvalue of type 'const int*'
     const int *& n1 = b1;
                       ^
stdout
Standard output is empty