Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void WorkP(int* data) {
- *data = 69;//we use *data to get the value where is it pointing
- }
- void WorkR(int& data) {
- data = 69;//we set the thing its refrencing to 69
- }
- int main() {
- //Pointers
- int x = 10;//the thing y is going to be pointing too
- int* y = &x;//We have to set the pointer to the location of x
- cout << x << " " << *y << endl;//prints what is x and y
- cout << "Memory location of x or where Y is pointing looks like this: " << y << endl;//Example of how a memory location looks
- WorkP(y);//Executes the function
- cout << x << " " << *y << endl;//prints again
- //Refrences
- int a = 10;
- int& b = a;
- //To get memory location of the refrence b we use &b
- cout << a << " " << b << endl;
- WorkR(b);
- cout << a << " " << b << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement