Guest User

Untitled

a guest
Jun 25th, 2019
54
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void main()
  2. {
  3. const int ANSWER = 42;
  4. int i = 0;
  5.  
  6. //ANSWER = 43; // Can't assign to constant
  7. const int *cp;
  8. cp = &ANSWER;
  9. //*cp = 43; // cp points to a (const int)
  10. cp = &i; // cp's contract allows to modify its contents
  11. i = 1;
  12. //*cp = 2; // cp's contract is not to modify the referenced value
  13.  
  14. // Assignint to const, the evil way:
  15. int *p;
  16. p = &ANSWER; // Warning only (error in C++)
  17. *p = 43;
  18. }
RAW Paste Data