# ConstCPP / ConstCPPTests / examples.cpp

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80``` ```extern "C" { int printf( char *, ...); } int f() { int a = 0; // <- const int a = 0; mutable int b = 1; // <- int b = 1; b = 2; return a + b; } struct Normal { mutable int a, b; Normal() : a(0), b(0) {} ~Normal() {} }; int f2() { mutable Normal n,n2; n.a = 1; n.b = 1; n2 = n; return n2.a + n2.b; } struct PartMutable { int a; mutable int b; PartMutable() : a(0), b(0) {} PartMutable(int a, int b) : a(a), b(b) {} ~PartMutable() {} }; int f3() { mutable PartMutable n; n.b = 1; return n.a + n.b; } struct NotMutable { int a, b; NotMutable() : a(0), b(0) {} NotMutable(int a, int b) : a(a), b(b) {} ~NotMutable() {} int getA() { printf("Not mutable\n"); return a + 1; } int getA() mutable { printf("Mutable\n"); return a - 1; } }; int f4() { mutable NotMutable n; NotMutable n2; return n2.getA() + n.getA(); } int f5(int* p) { return *p; } int f5(mutable int* p) { *p = 1; return 0; } int f5() { mutable int a = 10; int b = 15; int r1 = f5(&a); int r2 = f5(&b); if (r1 == 0 && a == 1 && r2 == 15) return 1; return 0; } int main(int argc, char** argv) { if (!(f() == 2 )) return 1; if (!(f2() == 2 )) return 1; if (!(f3() == 1 )) return 1; if (!(f4() == 0 )) return 1; if (!(f5() == 1 )) return 1; } ```