有以下程序 #include <stdio.h> void func( int n ) { static int num = 1; num += n; printf("%d ", num); } main() {

admin2021-02-25  12

问题 有以下程序
#include <stdio.h>
void  func( int  n )
{  
    static int  num = 1;
    num += n;   
    printf("%d ", num);
}
main()
{   
    func(3);   
    func(4);   
    printf("\n");  
}
程序运行后的输出是

选项 A、4 5
B、4 8
C、3 5
D、3 4

答案B

解析 本题中num为静态局部变量,执行fun(3)后,输出4,执行fun(4)后输出8,所以选项B正确。
转载请注明原文地址:https://kaotiyun.com/show/Zotp777K
0

最新回复(0)