Sunday, January 2, 2011

Mac OSでC言語を使用する場合のsizeof演算子について

Mac OSでC言語を使用する場合のsizeof演算子について、
戻り値の型が'long unsigned int'となるため、
『%ld』を使用し、値を受けて取る。

/* "struct Car" Declaration */

typedef struct Car {

int num;

double gas;

} Car;


int main(void) {

printf("the size of integer is %ld.\n", sizeof(int));

printf("the size of double is %ld.\n", sizeof(double));

printf("the size of struct Car is %ld.\n", sizeof(Car));

printf("the size of pointer of struct Car is %ld.\n", sizeof(Car *));


return 0;

}





No comments:

Post a Comment