一.宏定义必须写在函数外 #define s(y) y*y
二.如要终止其作用域可使用#undef命令
三.宏 名与形参表之间不可以有空格 #define Max (a,b) 是错误的
四.常考内容——用宏定义计算两者大小的值
#include<dtdio.h>
#define Max(a,b) (a>b)?a:b
void main ()
{
int x,y,max;
printf("input your numbers:");
scanf("%d %d",&x,&y);
max=Max(x,y);
printf("Thn max is :&d",max);
}
五.结构体的一般形式
Struct 结构体名
{
成员列表 //每个成员必须作类型说明 如 类型说明符 成员名;
};
Struct 结构体名
{
成员列表 //每个成员必须作类型说明 如 类型说明符 成员名;
}变量名列表;
六.结构体嵌套
#include<stdio.h>
#include<string.h>
void main()
{
struct date
{
int month;
int year;
int day;
};
struct
{
int num;
int name[10];
struct date birthday; //生日又是一个结构体变量,里面有month year day
} boy1,boy2;
printf("please input birthday(yy):");
scanf("%d",&boy1,birthday,year);
}
不可以将结构体便令作为一个整体进行输入输出,只可以是boy1.num这种形式
初始化
struct
{
int num;
int name[10];
char sex
} boy1,boy2={102,“hahhh”,‘m’};
七.结构体指针
#include<stdio.h>
#include<string.h>
struct stu
{
int num;
char *name;
char sex;
float score;
}boy1={102,"mmm",'m',65.5};
void main()
{
struct stu *p;
p=&boy1;
printf("Number is %d\n name is %s\n",(*p).num,(*p).name);
printf("Number is %d\n name is %s\n",p->um,p->name);
}