C++ Function Parameter Change an object by passing a pointer to object
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; class Employee//w w w .ja v a 2s .c o m { public: int workHour; double salary; }; void myFunction(Employee* pS) { pS->workHour = 10; pS->salary = 3.0; cout << "The value of pS->salary = " << pS->salary << endl; } int main(int nNumberofArgs, char* pszArgs[]) { Employee s; s.salary = 0.0; cout << "The value of s.salary = " << s.salary << endl; cout << "Calling myFunction(Employee*)" << endl; myFunction(&s); cout << "Returned from myFunction(Employee*)" << endl; cout << "The value of s.salary = " << s.salary << endl; return 0; }