C语言——宏定义、结构体知识点

1 篇文章 0 订阅
1 篇文章 0 订阅

一.宏定义必须写在函数外  #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);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值