Current location - Loan Platform Complete Network - Big data management - How to loop through an array in C
How to loop through an array in C
#include <stdio.h>

#include<stdlib.h>

struct s

{int a[2];

struct s *next;

}; //defines a structure

main()

{ int i=0;

struct s *head,*p;

head=p=(struct s *)malloc(sizeof(struct s));//open a new cell

for(i=0;i<2;i++) //define i<2, (if you want 100 arrays, i is equal to 100) similar to when you define 2 one-dimensional arrays

{

scanf("%d",p->a);

p=p->next=(struct s *)malloc(sizeof(struct s ));

}

p=head;//make the p pointer point to the first array

printf("%d\n",p->a[0]);//if you want to see the value of a[0] in the second array change it to (p->a[0])+1.

}