1. 字符串"abc"与{'a','b','c'}:
#include<stdio.h>
#include<string.h>//字符串string
int main()
{
char arr[] = "abc";//c后面有个\0
char arr2[] = {'a','b','c'};
printf("%s\n", arr);
printf("%zd\n", strlen(arr));//3
printf("%zd\n", strlen(arr2));//42
return 0;
}
?2.转义字符:
int main()
{
printf("%zd\n", strlen("c:\test\114\bbc"));//10 \t,\114,\b分别为一个转义字符
return 0;
}
?3.布尔类型(_Bool):
#include<stdio.h>
#include<stdbool.h>//布尔类型头文件
int main()
{
bool flag = true;//flag初始化值为true
if (flag)
printf("YES\n");
else
printf("NO\n");
return 0;
}
4.各个变量名的sizeof:
int main()
{
printf("%zd\n", sizeof(char));//1
printf("%zd\n", sizeof(short));//2
printf("%zd\n", sizeof(int));//4
printf("%zd\n", sizeof(long));//4
printf("%zd\n", sizeof(long long));//8
printf("%zd\n", sizeof(float));//4
printf("%zd\n", sizeof(double));//8
printf("%zd\n", sizeof(long double));//8
printf("%zd\n", sizeof(_Bool));//1
int a = 10;
printf("%zd\n", sizeof(int));//4
printf("%zd\n", sizeof(a));//4
return 0;
}
?
5.unsigned的使用:
int main()
{
/*signed int a =50000;*/
int a = -10;//有符号整数
unsigned int b = 10;
unsigned long int c = 100;
unsigned long long int d = 1000;
printf("%u\n", a);//a为负数,unsigned代表零和正整数
printf("%u\n", b);//10
printf("%lu\n", c);//100
printf("%llu\n", d);//1000
return 0;
}
?
6.全局变量与局部变量:
int b = 200;//全局变量
int main()
{
int a = 100;//局部变量
{
printf("%d\n", a);
int c = 20;//局部变量
}
//printf("%d\n", c);//c为局部变量
return 0;
}
int a = 100;
int main()
{
int a = 10;
printf("%d\n", a);//a=10,局部变量和全局变量冲突的时候,局部变量优先
return 0;
}
7.(1).整数除法和小数除法:
int main()
{
//除号的两端如果都是整数,执行的是整数除法
//如果要计算出小数的效果,那么除号的两端至少有一个数得是浮点数
//%f和%lf打印的时候小数点后默认打印6位小数
printf("%d\n", 15 / 3);//5
printf("%d\n", 5 / 2);//2
printf("%lf\n", 5.0 / 2.0);//2.500000
printf("%lf\n", 3.0 / 2.0);//1.500000
printf("%.1lf\n", 5.0 / 2.0);//2.5
printf("%.2lf\n", 3.0 / 2.0);//1.50
return 0;
}
?
(2)?/与%的用法:
int main()
{
int a = 7 / 2;//3 /--求商
int b = 7 % 2;//1 %--求余
printf("%d\n", a);
printf("%d\n", b);
return 0;
}
int main()//结果的正负号与被除数也就是11或者-11有关
{
printf("%d\n", 11 % -5);//1
printf("%d\n", -11 % -5);//-1
printf("%d\n", -11 % 5);//-1
return 0;
}
???????study_1_18/study.c · 羊村懒大王/study.2024 - 码云 - 开源中国 (gitee.com)