C语言学习【多个函数调用、调试程序】
函数调用
/* 一个文件中包含两个函数 */
#include "stdio.h"
void butler(void); /* ANSI/ISO C函数原型 */
int main(void)
{
printf("I will summon the bulter function. \n");
butler();
printf("Yes. Bring me some tea and writeable DVDs. \n");
return 0;
}
void butler(void) /* 函数定义开始 */
{
printf("You rang, sir?\n");
}
程序运行结果
I will summon the bulter function.
You rang, sir?
Yes. Bring me some tea and writeable DVDs
butler()
函数在程序中出现了3次:
第一次是函数原型(prototype)
或函数声明(function declaration)
,告知编译器在程序中要使用该函数;
第二次以函数调用(function call)
的形式出现在main()
中;
最后一次出现在函数定义(function definition)
中,函数定义即是函数本身的源代码。
无论main()
在程序文件中处于什么位置,所有的C
程序都从main()
开始执行
调试程序
#include "stdio.h"
int main(void)
{
int n, n2, n3;
n = 5;
n2 = n * n;
n3 = n2 * n2;
printf("n = %d, n squared = %d, n cubed = %d\n", n, n2, n3);
return 0;
}
程序运行结果
n = 5, n squared = 25, n cubed = 625
关键字和保留标识符
关键字
是C语言的词汇,不能用它们作为标识符,许多关键字用以指定不同的类型,如下图所示,粗体表示C90
标准新增关键字,斜体表示C99
标准新增关键字,粗斜体表示C11
标准新增关键字
![](https://img-blog.csdnimg.cn/img_convert/792baaedea2e7219c1a08ed112bf4c32.png)
![](https://img-blog.csdnimg.cn/img_convert/75bb31e0fd394e4a68fb16861899258d.png)
保留标识符包括以下划线字符开头的标识符和标准库函数,例如printf()