Advertisement
Touch_Grass

Untitled

Jan 7th, 2023
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | Source Code | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. void WorkP(int* data) {
  4.     *data = 69;//we use *data to get the value where is it pointing
  5. }
  6. void WorkR(int& data) {
  7.     data = 69;//we set the thing its refrencing to 69
  8. }
  9. int main() {
  10.     //Pointers
  11.     int x = 10;//the thing y is going to be pointing too
  12.     int* y = &x;//We have to set the pointer to the location of x
  13.     cout << x << " " << *y << endl;//prints what is x and y
  14.     cout << "Memory location of x or where Y is pointing looks like this: " << y << endl;//Example of how a memory location looks
  15.     WorkP(y);//Executes the function
  16.     cout << x << " " << *y << endl;//prints again
  17.     //Refrences
  18.     int a = 10;
  19.     int& b = a;
  20.     //To get memory location of the refrence b we use &b
  21.     cout << a << " " << b << endl;
  22.     WorkR(b);
  23.     cout << a << " " << b << endl;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement