Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. /*"To handle cases where the value of a "variable" that is initialized with a value that is not known at compile time but never changes after initialization, C++ offers a second form of costant (a const)"*/
  2.  
  3. constexpr int max = 100;
  4.  
  5. void use(int n)
  6. {
  7. constexpr int c1 = max+7; //OK: c1 is 107
  8. const int c2 = n+7; //OK, but don't try to change the value off c2
  9. //...
  10. c2 = 7; //error: c2 is a const
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement