指针存放的不是地址吗,为什么输出的却是字符?
#include<iostream.h>#include<string.h>
class teacher
{private:
char *name;
int age;
public:
teacher(char *i,int j)
{name=new char[strlen(i)+1];
strcpy(name,i);
age=j;
cout<<"\n 调用teacher";
}
~teacher()
{delete name;
cout<<"\n 调用~teacher"<<endl;
}
void show();
};
void teacher::show()
{
cout<<"\n name is:"<<name<<"year is:"<<age;//此处name输出的为什么是flydreams而不是name的地址?????
}
void main()
{teacher obj("flydreams",27);
obj.show();
}