为何我这个会出错?
#include<iostream>#include<iomanip>
#include<cstdio>
#include<cstdlib>
#define k 2
using namespace std;
int main()
{
struct abc
{
char name[20];
int age;
}*s,*s1;
int j;
s=new struct abc[k];
if(s==NULL) abort();
s1=s;
cout<<"*s=\n";
for(j=0;j<=k-1;j++)
{
cin>>s->name>>s->age;
cout<<s->name<<" "<<s->age<<"\n";
s++;
}
delete s1;
char a[3][10],*p[3];
int i;
for(i=0;i<=2;i++)
p[i]=a[i];
for(i=0;i<=2;i++)
{
cout<<"a["<<i<<"]=";
gets(p[i]);
}
cout<<endl;
for(i=0;i<=2;i++)
{
puts(a[i]);
puts(p[i]);
cout<<"a["<<i<<"]="<<a[i]<<endl;
cout<<"p["<<i<<"]="<<p[i]<<endl;
cout<<"&a["<<i<<"]="<<&a[i]<<endl;
cout<<"&p["<<i<<"]="<<&p[i]<<endl;
printf("%.3s\n",p[i]);
cout<<*(a+i)+2<<endl;
}
return 0;
}
本来我单独写下面一段没错,后来又新做了一题写了
struct abc
{
char name[20];
int age;
}*s,*s1;
int j;
s=new struct abc[k];
if(s==NULL) abort();
s1=s;
cout<<"*s=\n";
for(j=0;j<=k-1;j++)
{
cin>>s->name>>s->age;
cout<<s->name<<" "<<s->age<<"\n";
s++;
}
delete s1;
这一段,好像这段和后面的没有什么影响 ,可是为什么下面那段的程序受到影响出错了呢?