/* int 4个字节 %d long 8个字节 %ld long long 8个字节 %lld short 2个字节 %d signed unsigned */ #include <stdio.h> int main() { // int a = 11111119080980808;超过int所占的内存大小,编译器警告 long int a =222222222899908800l; long long int b =88888888889908800ll; //long int可以直接写成long printf("%ld\n%lld\n", a, b); //输出时应该写“%ld" //long long int 也可以写成 long long,输出时写“%lld" /*在32位编译器环境下long是4位,long long 是8个字节,在64位编译 器环境下long和long long是一样的都是8个字节*/ /*short int a = 10可以写成short a = 10 输出是“%d"*/
//输出字符字节:sizeof() int s = sizeof(int); printf("%d\n",s);
/*signed最高位要当作符号位(表示正负) unsigned最高位不当作符号位 signed == signed int (其实int默认就是有符号,平时不写signed) 有符号:正数/0/负数 signed int a = 10 也可以写成signed a = 10
unsigned int b = 5 也可以写成unsigned b = 5 无符号:0/正数*/
/*signed和unsigned可以和long、short一起用 例如: long unsigned int c = 4 long unsigned = 4 short unsigned int = 5 short unsigned = 5 但是long和short不可以一起用,会报错的 */
//signed和unsigned是不会改变字节数的,只会改变最高位是否做符号位
//输出unsigned是用“%u” unsigned e = 10; printf("%u\n",e);
return 0; }
|