Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class test_struct {
- public:
- int i;
- const int j;
- };
- int main() {
- cout << "Create a struct with int i = 100 and const int j = 101." << endl;
- test_struct test{100, 101};
- cout << test.i << endl;
- cout << test.j << endl;
- cout << "Create pointer p and point it to int i." << endl;
- int* p1 = &test.i;
- cout << *p1 << endl;
- cout << "Increment pointer p, which should now be pointing at const int j." << endl;
- p1++;
- cout << *p1 << endl;
- cout << "Dereference p and increment it." << endl;
- (*p1)++;
- cout << *p1 << endl;
- cout << test.j << endl;
- }
- Create a struct with int i = 100 and const int j = 101.
- 100
- 101
- Create pointer p and point it to int i.
- 100
- Increment pointer p, which should now be pointing at const int j.
- 101
- Dereference p and increment it.
- 102
- 102
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement