《C语言及程序设计》程序阅读——程序的多文件组织

    xiaoxiao2025-10-13  2

    返回:贺老师课程教学链接

    1、写出下面程序的运行结果

    #include <stdio.h> int a=3, b=5; int max(int a,int b) { int c; c=a>b ? a : b; return c; } int main() { int a=8; printf("%d\n",max(a,b)); return 0; }

    2、下面的程序,有两个源文件,编译时会出现错误 (1)请解释错误的原因 (2)在两个文件的第二行做些改动,均可以避免这个错误,试着改一下,分别说出其

    运行结果 file.c

    #include <stdio.h> static int n; void fn(); int main() { n=20; printf("%d\n", n); fn(); return 0; }

    file2.c

    #include <stdio.h>  extern int n; void fn() { n++; printf("%d\n", n); }

    提示:改法1——file1.c中去掉static,file2.c不变,file2.c中将使用file1中的变量;改法2——file1.c不变,file2.c中去掉extern,file2.c将使用本文件中的全局变量n

    相关资源:python入门教程(PDF版)
    最新回复(0)