공부/C언어
22. 구조체 배열 변수 선언
유저라인
2019. 7. 10. 13:55
728x90
반응형
1.head_t.h
#include <stdio.h>
typedef struct
{
int TextColor;
int BackColor;
}test1;
#define test_val 2
2. main.c
#include "head_t.h"
static int act_val = 0;
test1 test1_1[test_val];
void main(void)
{
act_val = 0;
test1_1[act_val].BackColor = 10;
printf("test[0] = %d\r\n", test1_1[0].BackColor);
printf("test[1] = %d\r\n", test1_1[1].BackColor);
printf("test[2] = %d\r\n", test1_1[2].BackColor);
act_val = 1;
test1_1[act_val].BackColor = 20;
printf("test[0] = %d\r\n", test1_1[0].BackColor);
printf("test[1] = %d\r\n", test1_1[1].BackColor);
printf("test[2] = %d\r\n", test1_1[2].BackColor);
}
3. 결과화면
728x90
반응형