#include<stdio>
int main()
{
int a=3;
int b=12;
int ma =0;
ma=(a>b?a:b);
printf("%d\n",ma);
return 0;
}
11.常见关键字(define不是关键字,是一种指令)
常见:auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while
11.关键字typedef(类型定义,即类型重命名,取了个别名)
#include<stdio>
int main()
{
typedef unsigned int u_int;
unsigned int num1=20;
u_int num2=20;
printf("%d\n",num1);
printf("%d\n",num2);
return 0;
}
#define MAX 1000 //define定义标识符常量
#define ADD(x,y) ((x)+(y)) //define定义宏
int main()
{
int sum = ADD(2,3);
printf("sum=%d\n",sum); //函数的方式
sum =ADD(2,3); //宏的方式
printf("sum=%d\n",sum);
return 0;
}
13.指针
*解引用操作符/间接访问操作符 即:*p对p进行解引用操作,找到它所指向的对象a
#include<stdio>
#include<string>
int main()
{
int a=10;
int* p=&a;
* p=20;
printf("%p\n",&a);
printf("%p\n",p);
return 0;
}
14.结构体(用来描述复杂类型)
#include<stdio>
#include<string>
struct bok
{
char name[20];
short price;
};
int main()
{
struct bok b1={"乱七八糟",90};
struct bok* pb=&b1;
b1.price=33; //变量可以轻易修改
strcpy(b1.name,"cs++"); //name是数组,数组的本质是一个地址 return 0;
}