常量可以分为以下几种:
.字面常量如:3.14,5,-10,“abcdrd”;
.1.2const: 修饰的常变量:这时候const修饰的相对于一个常属性的变量,下面的num1本质还是一个变量,但是由于const修饰所以变成了常变量。#include.1.3#define 定义的标识符常量:写法——#define MAX(自己定义)1000(自己输入的数值)int main() { //const修饰的常变量 int num = 10; num = 20;//num是变量可以发生变化 printf("%dn",num); const int num1 = 20;//当用const修饰,就不能发生改变。 num1 = 70; printf("%d",num1); return 0; }
#include.1.4枚举常量——一一列举:enum是枚举的关键字#define num 5 int main() { int arr[num]={};//这里与const有所不同!!! return 0; }
#include2.1字符串 用一对单引号引起来的就是字符如:'A','abc','$','3'(字符3,区分数字3),电脑是用二进制输出的。一对双引号引起来的叫字符串如:“zhangxi”,"大大"。注意:字符串的结束标志为 的转义字符,是结束标志,不算内容enum colok { red,//0 里面的内容用逗号,隔开!!! yellow,//1 blue,//2 里面的初始值可以修改 green=9 //这时green值就为9 }; int main() { enum colok s=red; enum colok s1=blue; printf("%d %dn",s,s1);//默认输出red yellow blue 为0 1 2.所以s为0,s1为2 return 0; }
#include.2.2转义字符——转变意思 .2.3注释int main() { //字符串结束标志为/0 char arr[]={"abcde"}; char arr1[]={'a','b','c','d','f'}; printf("%s",arr);输出为abcde printf("%s",arr1);s输入为错误形式,这是因为字符串以/0为结束标志,如果字符后面加上'/0',就是一样的结果 return 0; }
不会在编译器上出现的内容,不需要的部分,可以删除也可以注释。有难懂的代码可以注释解释文字。可以用//注释掉单行内容,可以单行也可以多行,不支持嵌套。
3.1选择语句——用if switch语句if语句
#includeint main() { int a=0;//if语句 int b=0; scanf("%d %d",&a,&b);//取地址就是可以自己在编译器上输入内容 if(a>b) printf("hahan"); else printf("hehen"); return 0; }
switch语句
.4.1函数#include.5.1数组定义 int arr[5]={1,2,3,4,5};//定义一个整型数组,最多存放5个元素。 .5.2数组的下标 C语言规定:数组的每一个元素都有一个下标,下标从0开始int add(int x, int y)//函数求两个数相加 { int z = x + y; return z; } int main() { int a=0; int b=0; scanf("%d %d",&a,&b); int sum = add(a,b); printf("%d",sum); return 0; }
int arr[10]={0};//有十个元素,但是内容都为0



