Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class test_struct {
  6. public:
  7. int i;
  8. const int j;
  9. };
  10.  
  11. int main() {
  12. cout << "Create a struct with int i = 100 and const int j = 101." << endl;
  13. test_struct test{100, 101};
  14. cout << test.i << endl;
  15. cout << test.j << endl;
  16. cout << "Create pointer p and point it to int i." << endl;
  17. int* p1 = &test.i;
  18. cout << *p1 << endl;
  19. cout << "Increment pointer p, which should now be pointing at const int j." << endl;
  20. p1++;
  21. cout << *p1 << endl;
  22. cout << "Dereference p and increment it." << endl;
  23. (*p1)++;
  24. cout << *p1 << endl;
  25. cout << test.j << endl;
  26. }
  27.  
  28. Create a struct with int i = 100 and const int j = 101.
  29. 100
  30. 101
  31. Create pointer p and point it to int i.
  32. 100
  33. Increment pointer p, which should now be pointing at const int j.
  34. 101
  35. Dereference p and increment it.
  36. 102
  37. 102
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement