1、int float double char [signed unsigned short long (long long)]修饰int时,都可省略int, 2、作用:说明一个变量的类型,便于区分及优化内存
3、 signed -->能修饰 int和char %d unsigned -->能修饰 int 和char %u short -->能修饰 int %d 在16/32/64位编译器下都是2个字节 long ---->能修饰 int和 double(%Lf) %ld 16/32--4字节 64--8字节 long long -->能修饰 int lld% 在16/32/64位编译器下都是8个字节
**浮点型只有有符号类型,没有无符号类型 **signed 和 unsigned都不能修饰float 和 double 浮点型
4、类型说明符可以累加,如果省略了基本数据类型,那么基本数据类型是int 5、注意:long short long long 等不可同时使用 6、有符号的char类型是(-128~127)signed char (signed可省略) 无符号的char类型是(0~255) unsigned char
#include <stdio.h> int main(){ //1、省略int short a = 2;//short int a printf("%d\n",a); long b = 8;//long int b printf("%ld\n",b); long long c = 8;//long long ing c printf("%lld\n",c);
//2、long 能修饰double long double d = 8;//正确 8.000000 printf("%Lf",d);
long long double e = 8;//错误 long long 不能修饰double short double f = 2;//错误 short 不能修饰double
short float g = 2;//错 long float h = 8;//错 long long float i = 8;//错
short char ch = 0;//错误 long char ch1 = 0;//错误 long long char ch2 = 0;//错误
//3、类型说明符可以累加,如果省略了基本数据类型,那么基本数据类型是int
signed long r = 0;//== signed long int unsigned long r1 = 0;// == unsigned long int long e = 0;//== signed long int unsigned short o = 0;//unsigned short int unsigned long long q = 0;// unsigned long long int
//4、注意:long short long long 等不可同时使用 long short a3 = 0;//错误
//5、 有符号的char类型是(-128~127) //无符号的char类型是(0~255) unsigned char cc = -4; printf("%u\n",cc);//252
char cc1 = 255; printf("%d\n",cc1);//-1
char cc2 = 127; printf("%d\n",cc2);//127
//**signed 和 unsigned都不能修饰float 和 double signed float f1 = 0;//错 unsigned float f2=0;//错 signed double d1 = 0;//错 unsigned double d2 =0;//错
return 0; }
|