SLE5 课堂内容:为啥我输出的long int 占8个字节呢
本帖最后由 ziqiyang 于 2018-9-4 17:43 编辑<#include<stdio.h>
int main()
{
printf("int = %lu\n",sizeof(int));
printf("short int = %d\n",sizeof(short));
printf("long int = %d\n",sizeof(long));
printf("long long int = %d\n",sizeof(long long));
printf("char = %d\n",sizeof(char));
printf("_Bool = %d\n",sizeof(_Bool));
printf("float = %d\n",sizeof(float));
printf("double = %d\n",sizeof(double));
printf("long double = %d\n",sizeof(long double));
return 0;
}>
输出结果是<int = 4
short int = 2
long int = 8
long long int = 8
char = 1
_Bool = 1
float = 4
double = 8
long double = 16
Program ended with exit code: 0>
带你学C带你飞第6课,跟着小甲鱼老师打的,没问题,输出确实long int占8个字节,不明白了.
顺便问下,我用的XCODE, 这个程序里所有printf语句都提示“Format specifies type 'int' but the argument has type 'unsigned long'”
求老鸟指导 long只能保证 大于等于 int
不同机器的结果不一样 printf("int = %lu\n",sizeof(int));//应该是 %d
其实是要看机器与编译器的位元数,再来是看编译器。因为没有严格规定~ 你的编译器是64位的,就会这样
页:
[1]