diff options
author | Oskar <[email protected]> | 2024-09-17 15:02:56 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-09-17 15:02:56 +0200 |
commit | d8d8f1c987f118843d44ea27ac516f8fe866ded4 (patch) | |
tree | 0489d8d0565c8941422358e52dc6394cbf03db86 /const-pointer-tests.cpp | |
parent | c640d847343b3d50e7716173141d63bd1cca265c (diff) |
more
Diffstat (limited to 'const-pointer-tests.cpp')
-rw-r--r-- | const-pointer-tests.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/const-pointer-tests.cpp b/const-pointer-tests.cpp new file mode 100644 index 0000000..dceda16 --- /dev/null +++ b/const-pointer-tests.cpp @@ -0,0 +1,24 @@ +#include <iostream> + +/* + * + * Trying to make sense of const + * + * + */ + +int main () { + int a = 0; + int b = 0; + int c = 0; + int const* pointer1 = &a; // Cannot change underlying object, can point to other object (Please for the love of god dont use this version its so confusing, use pointer3 version instead because its the same thing and much more clear + int *const pointer2 = &b; // Can change underlying object, can not point to new object + const int* pointer3 = &c; // Cannot change underlying object, can point to other object + std::cout << pointer1 << "\n" + << pointer2 << "\n" + << pointer3 << std::endl; + + const int *const pointer4 = &a; // Cannot change underlying object, cannot point to another object + std::cout << pointer4 << std::endl; + return 0; +} |