提高可读性的技巧、多函数处理——the third study--2022.12.20

提高程序可读性的四个技巧

1. 选择有意义的函数名。(例如:身高--height;体重--weight;英寸--foot等等)

2. 写注释。当有些函数名不好解释时,可以通过在旁边写注释来进行解释;也可以在一些复杂语句后面进行注释,来表明写这句语句是为什么。

3. 在函数中用空行分隔概念上的多个部分。

4. 每条语句各占一行。

 

多个函数处理

例如:


#include <stdio.h>

void buter(void);      /*函数原型(prototype)*/

int main(void)

{

printf("I will  summon the butler function.\n");

butler();        /*函数调用(function call)*/

printf("Yes.Bring me some tea and writeable DVDs.\n");

 

return 0;

}

void butler(void)         /*函数定义(function definition)*/

{

printf("You rang,sir?\n");

}


 

输出结果:

I will summon the butler function.

You rang,sir?

Yes.Bring me some tea and writeable DVDs.

 

定义任意变量打印


 

#include <stdio.h>
#define Name "Jack"
#define Surname "Soni"

int main(void) {

printf("%s %s\n", Name, Surname);
printf("%s\n%s\n", Name, Surname);
printf("%s", Name);
printf(" s\n", Surname);

return 0;
}


 

输出结果:

Jack Soni

Jack

Soni

Jack Soni

 

posted @ 2022-12-24 21:23  江理第一深情  阅读(74)  评论(0)    收藏  举报