1 #include <stdio.h>
2
3
4 struct test {
5 char c;
6 int i;
7 double d;
8 void *p;
9 int a[0];
10 };
11
12 int main (void) {
13 struct test t;
14 printf("size of struct is: %d\n", sizeof(t));
15 return 0;
16 }
출력 :구조의 크기
size of struct is: 20
이 왜 int a[0]
고려하지?
1 #include <stdio.h>
2
3
4 struct test {
5 int a[0];
6 };
7
8 int main (void) {
9 struct test t;
10 printf("size of struct is: %d\n", sizeof(t));
11 return 0;
12 }
출력 :
size of struct is: 0
a[0]
는 구조 부재이다. 그렇다면 어떻게 구조의 크기로 간주되지 않습니까?
int a [0]'의 크기는 어느 정도입니까? – glglgl
그냥 자연스럽게 추측합니다 - a [0]은 요소가 0 인 배열이고 논리 크기는 0이됩니다. –
int a [0]은 정수를 메모리에 저장합니다. – Nocturno