f) 一个指向有10个整型数数组的指针(A pointer to an array of 10 integers)
g) 一个指向函数的指针,该函数有一个整型参数并返回一个整型数(A pointer to a function that takes an integer as an argument and returns an integer)
h) 一个有10个指针的数组,该指针指向一个函数,该函数有一个整型参数并返回一个整型数( An array of ten pointers to functions that take an integer argument and return an integer )
答案是:
e) int *a[10]; // An array of 10 pointers to integers
f) int (*a)[10]; // A pointer to an array of 10 integers
g) int (*a)(int); // A pointer to a function a that takes an integer argument and returns an integer
h) int (*a[10])(int); // An array of 10 pointers to functions that take an integer argument and return an integer
#include
#include
int main(void) {
typedef union {long i; int k[5]; char c;} DATE;
struct date { int cat; DATE cow; double dog;} too;
DATE max;
int b[5];
printf("struct %d\n", sizeof(struct date) );
printf("union %d\n", sizeof(DATE));
printf("double %d\n", sizeof(double));
printf("long %d\n", sizeof(long));
printf("array int %d\n", sizeof(b));
//actual result is 40 24 8 8 20
}
sizeof
long 8, double 8, long long 8, short 2
64位机上测试的结果:
Summary: struct and union has common point, 大小永远为里面最大类型(max=8)的倍数,
struct 按照最大类型的大小来判断是否需要补齐。
No comments:
Post a Comment