C语言怎样循环创建数组

如题所述

#include
<stdio.h>
#include<stdlib.h>
struct
s
{int
a[2];
struct
s
*next;
};
//定义了一个结构体
main()
{
int
i=0;
struct
s
*head,*p;
head=p=(struct
s
*)malloc(sizeof(struct
s));//开辟一个新单元
for(i=0;i<2;i++)
//定i<2,(如果你想要100个数组,i
就等于100)类似于你定义了2个一维数组
{
scanf("%d",p->a);
p=p->next=(struct
s
*)malloc(sizeof(struct
s));
}
p=head;//使p指针指向第一个数组
printf("%d\n",p->a[0]);//如果你想看第二个数组里的a[0]的数值改成(p->a[0])+1。
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2020-04-24
#include
<stdio.h>
#include<stdlib.h>
struct
s
{int
a[2];
struct
s
*next;
};
//定义了一个结构体
main()
{
int
i=0;
struct
s
*head,*p;
head=p=(struct
s
*)malloc(sizeof(struct
s));//开辟一个新单元
for(i=0;i<2;i++)
//定i<2,(如果你想要100个数组,i
就等于100)类似于你定义了2个一维数组
{
scanf("%d",p->a);
p=p->next=(struct
s
*)malloc(sizeof(struct
s));
}
p=head;//使p指针指向第一个数组
printf("%d\n",p->a[0]);//如果你想看第二个数组里的a[0]的数值改成(p->a[0])+1。
}本回答被提问者采纳
第2个回答  2021-03-15

C语言的数组概念的学习,通过for循环输出打印数组