标题:为何我这个会出错?
取消只看楼主
w273732573
Rank: 1
等 级:新手上路
帖 子:6
专家分:5
注 册:2008-5-28
 问题点数:0 回复次数:0 
为何我这个会出错?
#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;
这一段,好像这段和后面的没有什么影响 ,可是为什么下面那段的程序受到影响出错了呢?
搜索更多相关主题的帖子: include 
2009-10-17 19:57



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-288925-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.420754 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved