3
I know these two ways to boot struct
's.
#include <stdio.h>
typedef struct {
char s[10];
int a, b;
double x;
} TIPO;
int main(){
TIPO v1[10]={"foo", 5, 13, 4.3, "bar", 0, 0, 2.3};
TIPO v2[10]={{"FOO", 10, 1, .3},{ "Barrr", 10, -20, 39.22}};
printf("%s : %d : %d : %.3lf\n", v1[0].s, v1[0].a, v1[0].b, v1[0].x);
printf("%s : %d : %d : %.3lf\n", v1[1].s, v1[1].a, v1[1].b, v1[1].x);
printf("%s : %d : %d : %.3lf\n", v2[0].s, v2[0].a, v2[0].b, v2[0].x);
printf("%s : %d : %d : %.3lf\n", v2[1].s, v2[1].a, v2[1].b, v2[1].x);
}
Upshot:
foo : 5 : 13 : 4.300
bar : 0 : 0 : 2.300
FOO : 10 : 1 : 0.300
Barrr : 10 : -20 : 39.220
What other ways to initialize structs
in C11/C18?
How to initialize, say, b=1
for all elements of v1
?