字符整型指针

来源:互联网 发布:弹珠汽水淘宝 编辑:程序博客网 时间:2024/04/29 20:51
#include<iostream>
using namespace std;
void main()
{


struct test{
char *str;
int *ip;
}x;






x.ip=new int;
*(x.ip)=100;
cout<<"x.ip:"<<x.ip<<'\t'<<*(x.ip)<<endl;
delete x.ip;
x.ip=new int[5];


for(int i=0;i<5;i++)
*(x.ip+i)=100+i;


cout<<"全部输出x.ip:"<<endl;
for(int i=0;i<5;i++)
cout<<x.ip+i<<'\t'<<(*(x.ip+i))<<endl;
delete x.ip;
x.str=new char('A');
cout<<"x.str:"<<(*x.str)<<endl;
delete x.str;
x.str=new char[5];
*x.str='G';
*(x.str+1)='o';
*(x.str+2)='o';
*(x.str+3)='d';
*(x.str+4)='\0';


cout<<"x.str:"<<x.str<<endl;
delete x.str;


test y={"Very Good!",NULL};
cout<<"y.str:"<<y.str<<endl;
cout<<"y.ip:"<<y.ip<<endl;


}
0 0
原创粉丝点击