fork download
  1. #include <iostream>
  2.  
  3. struct S {
  4. int a ;
  5. };
  6.  
  7. int main() {
  8. S s1;
  9. S s2;
  10. s1.a = 1;
  11. s2.a = 2;
  12.  
  13. const S* p = &s1;
  14. //p->a = 1; // does not work, read it from right to left as S const* p (pointer on constant S).
  15.  
  16. p = &s2;
  17. std::cout << p->a << std::endl;
  18. return 0;
  19. }
Success #stdin #stdout 0s 2728KB
stdin
Standard input is empty
stdout
2