常量
const
常属性,修饰变量使其变为常变量。
#include <stdio.h>
int main{
const int num = 10;
printf("%d\n",num);
return 0;
}
字面常量
#inclode <stdio.h>
int main(){
1;
2;
//其中1,2是字面常量
return 0;
}
枚举常量 ————列举
枚举常量关键————enum
#inclode <stdio.h>
enum Color{
red,
yellow,
blue
}
int main(){
enum Color color = blue;
return 0;
}
#define
定义的标识符常量
#include <stdio.h>
#define Max = 10;
int main(){
char a[Max] = {0};
return 0 ;
}
字符串类型
\0是字符串的结束,不算内容。
strlen()是计算字符串长度的 ,使用时要加#include <string.h>
用双引号引起来的字符。
#include <stdio.h>
int main{
"chshskfhk";
""; //空字符串
return 0;
}
可以用数组来存放字符串。
#include <stdio.h>
int main{
char a[] = "abc";
printf("%s\n",a);
return 0;
}
#include <stdio.h>
int main{
char a[] = "abc";
char a1[] = {'a','b','c','0'};
printf("%s\n",a);
printf("%s\n",a1);
//打印出来的a和a1内容是一样的。
return 0;
}
转义字符
#include <stdio.h>
#include <strig.h>
int main{
printf("%s\n","\"");打印出“ ,不加不打印
return 0;
}
int main{
printf("%d\n",strlen("c:\test\32\test.c"));//打印出13 --\t为一个,\32为一个
//\32--32是2个8进制数字
//32作为8进制代表的那个十进制数字,作为ASCII码值对应的字符
//32 -->10进制 26 ->作为ASCII码值代表的字符
return 0;
}
if...else 选择语句
#include <stdio.h>
int main{
int num;
printf("要不要好好学习?(1/0)>:")
scanf("%d",num);
if(num ==1){
printf("好");
}
else{
printf("并不好");
}
}
while 循环语句
#include <stdio.h>
int main(){
int a = 0;
while(a<=100){
printf("加油")
a++;
}
}
函数 ————自定义函数,库函数
#include <stdio.h>
int Add(int a,int b){
int z = a+b;
return z;
}
int main{
int s =10;
int d = 20;
sum = Add(a,d);
printf("sum=%d\n" ,sum)
return 0;
}
数组
#include <stdio.h>
int main{
//int a=1;
//int b=2;
//int c = 3;
int arr[10] = {1,2,3,4,5,6,7,8,9,10};//int arr[10]定义一个存放10个整数数字的数组
//char arr[10];
//.......
printf("%d\n",arr[4])//下标的方式访问元素
return 0;
}
arr : 1 2 3 4 5 6 7 8 9 10
下标:0 1 2...............