C语言学习【多个函数调用、调试程序】

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标准新增关键字

保留标识符包括以下划线字符开头的标识符和标准库函数,例如printf()

  • 18
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值