[ create a new paste ] login | about

Link: http://codepad.org/B0oUJuC8    [ raw code | output | fork ]

C++, pasted on Jan 13:
#include <iostream>

class A {

   public:
      int value;

};

void callByValuePtrAssign(A* a) {

   a = new A;
   a->value = 0;

}

void callByReferencePtrAssign(A* &a) {

   a = new A;
   a->value = 0;

}

int main() {

   A* a = new A;
   a->value = 3;

   cout << "Initial value:" << a->value << endl;

   callByValuePtrAssign(a);

   cout << "After call by value:" << a->value << endl;

   callByReferencePtrAssign(a);

   cout << "After call by reference:" << a->value << endl;
   
   return 0;
}


Output:
1
2
3
Initial value:3
After call by value:3
After call by reference:0


Create a new paste based on this one


Comments: