【20171022】

来源:互联网 发布:mac desktop pictures 编辑:程序博客网 时间:2024/05/18 13:31

【程序44】
题目:学习使用external的用法。

#include <stdio.h>int a,b,c;void add(){    int a;    a = 3;    c = a + b;}int main(int argc, char* argv[]){    a = b = 4;    add();    printf("The value of c is equal to %d\n",c);}

运行结果:

这里写图片描述

【程序45】
题目:学习使用register定义变量的方法。
//使用了register定义变量之后,就说明把定义的变量放在了寄存器的高速缓存中,运行速度非常快。测试了下,普通变量的话大概是14个光标闪动,register大概是两个左右。

#include <stdio.h>int main(int argc, char* argv[]){    register int i;    int tmp = 0;    for(i = 1;i <=100;i++)    {        tmp += i;        printf("The sum is %d\n",tmp);    }}

运行结果:

这里写图片描述

原创粉丝点击