大胖子930 发表于 2017-6-22 23:04:08

带你学C带你飞(S1E6)

1.数据类型
(1).基本数据类型:
整数类型(int)、浮点数类型(float\double)、字符类型(chart)、布尔类型(_Bool 真或假)、枚举类型
(2).指针类型
(3).构造类型:
数组类型、结构类型、联合类型
(4).空类型

2.sizeof运算符
用于获得数据类型或表达式的长度。
(1). -sizeof(object); //sizeof(对象);
(2).-sizeof(type_name); //sizeof(类型);
(3).-sizeof object; //sizeof 对象;

3.课堂代码案例1:
#include <stdio.h>

int main()
{
int i;
char j;
float k;

i = 123;
j = 'c';
k = 3.14;

printf("sizeof int is %d\n",sizeof(int));
printf("sizeof i is %d\n",sizeof(i));
printf("sizeof char is %d\n",sizeof(char));
printf("sizeof j is %d\n",sizeof(j));
printf("sizeof float is %d\n",sizeof(float));
printf("sizeof k is %d\n",sizeof(k));

return 0;
}

4.课堂代码案例2:
#include <stdio.h>

int main()
{
printf("int = %d\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;
}

5.signed和unsigned
限定char类型或者任何整型变量的取值范围。
signed表示该变量是带符号位;该变量可以存放负数。
unsigned表示该变量不带符号位。
short
short
int
int
long
long
long long
long long

6.课堂代码案例3:
#include <stdio.h>

int main()
{
short i;
unsigned short j;

i = -1;
j = 1;

printf("%d\n",i);
printf("%u\n",j);

return 0;
}
页: [1]
查看完整版本: 带你学C带你飞(S1E6)