
ryutenchi
By: a guest on Sep 7th, 2008 | syntax:
C++ | size: 1.87 KB | hits: 59 | expires: Never
/*
* pointer.cpp
*
* Copyright 2008 Unknown <system@SMOOTHMACHINE>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include <iostream>
using namespace std;
class people
{
public:
int getAge(){return age;};
void setAge(int a){age=a;};
protected:
int age;
};
int main(int argc, char** argv)
{
people* pPerson;
people me, you;
pPerson = new people();
pPerson->setAge(12);
me.setAge(274);
you.setAge(43);
cout<<"The pointer says: "<<pPerson->getAge()<<endl;
delete pPerson;
pPerson = &me;
cout<<"The pointer says: "<<pPerson->getAge()<<endl;
pPerson = &you;
cout<<"The pointer says: "<<pPerson->getAge()<<endl;
int* pAge;
int meAge, youAge;
pAge = new int();
*pAge = 12;
meAge = 274;
youAge = 43;
cout<<"The pointer says: "<<*pAge<<" It is stored at: "<<pAge<<endl;
delete pAge;
pAge = &meAge;
(*pAge)++;
cout<<"The pointer says: "<<*pAge<<" It is stored at: "<<pAge<<endl;
pAge = &youAge;
(*pAge)++;
cout<<"The pointer says: "<<*pAge<<" It is stored at: "<<pAge<<endl;
return 0;
}