C语言怎样循环创建数组

2025-04-14 00:54:16
推荐回答(2个)
回答1:

#include

#include
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:

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