Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <iostream>
- using namespace std;
- int main()
- {
- /*************************
- * declare the variables *
- *************************/
- int a, b; // int
- int e, f; // int
- int *c = &e; // int pointer
- int *d = &f; // int pointer
- /*****************
- * assign values *
- *****************/
- a = 5; // set a = 5
- b = 10; // set b = 10
- *c = 15; // set value pointed to by c = 15
- *d = 20; // set value pointed to by d = 20
- /*************************
- * display the variables *
- *************************/
- cout << "a: " << a << ", b: " << b << endl;
- cout << "c: " << c << ", d: " << d << endl;
- cout << "c points to: " << *c << endl;
- cout << "d points to: " << *d << endl;
- cout << endl;
- /***********************************
- * do stuff with the the variables *
- ***********************************/
- c = &a; // set c = the address of a
- d = &b; // set d = the address of b
- /****************************************
- * display the variables after changing *
- ****************************************/
- cout << "a: " << a << ", b: " << b << endl;
- cout << "c: " << c << ", d: " << d << endl;
- cout << "c points to: " << *c << endl;
- cout << "d points to: " << *d << endl;
- cout << endl;
- /****************************************
- * do more stuff with the the variables *
- ****************************************/
- *c = 25; // set the value pointed to by c (a) = 25
- *d = 30; // set the value pointed to by d (b) = 30
- /*******************************
- * display the variables again *
- *******************************/
- cout << "a: " << a << ", b: " << b << endl;
- cout << "c: " << c << ", d: " << d << endl;
- cout << "c points to: " << *c << endl;
- cout << "d points to: " << *d << endl;
- cout << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment