首页/ 题库 / [单选题]有下列程序void func1(int 的答案

有下列程序void func1(int i);void func2(int i);char st[ ]="hello,friend! ";void func1(int i){ printf("%c",st[i]); if(i<3){i+=2;func2(i);}}void func2(int i){ printf("%c",st[i]); if(i<3){i+=2;func1(i);}}main(){ int i=0;func1(i); printf("\n");}执行后的输出结果是A.hello B.helC.hlo D.hlm

单选题
2022-02-21 16:56
A、hello
B、hel
C、hlo
D、hlm
查看答案

正确答案
C

试题解析
根据变量作用域与其定义语句在程序中出现位置之间的关系,可把变量分为局部变量和全局变量两种。其中,在函数外部定义的变量叫做全局变量,又称为外部变量;在函数体内定义的变量是局部变量,又称为内部变量。全局变量的作用域是整个程序,而局部变量的作用域是定义它的函数或者程序段。在本题中,程序首先声明两个无返回值函数func1和func2,然后定义一个全局数组st。做这类除主函数外,有其他函数的试题时,首先需要分析其他函数来得知函数的作用,然后再看主函数。func1函数带有一个整型变量的形参,在函数体中,首先输出以形参作为下标的数组元素值,然后执行if条件判断语句,其条件为形参变量i<3。如果结果为真,则将变量i加2后保存,然后调用func2函数;如果条件结果为假,则结束该函数。从程序中不难看出,func2函数与func1函数基本类似,只是最后它对函数func1进行调用,与前者不同,两个函数是互相调用的。在主函数中定义一个变量i并赋值为0,然后调用函数func1,根据我们对函数func1的分析可知,输出st[0]即字符‘h’,而此时if语句的结果为真,执行i加2并调用func2函数操作。此时变量i的值为2,因此,输出st[2]即字符‘l’,此时函数func2中的if条件语句结果为真,同样执行i加2,并调用func1函数操作,然后通过func1函数输出st[4]即字符‘o’,此时由于变量i的值等于4,是大于3的,函数结束。程序运行到出口,最后输出换行。因此,本程序最终的输出结果是hlo。

标签:
感兴趣题目
有以下程序struct S{ int n; int a[20]; }; void f(int *a,int n) {int i; for(i=0;i a[i]+=i; } main() {int i; struct S s={10,{2,3,1,6,8,7,5,4,10,9}}; f(s.a, s.n); for(i=0;i printf(“%d”,s.a[i]); } 程序运行后的输出结果是( )。
有以下程序: struct S{int n;int a[20];}; void f(int*a,int n) {int i; for(i=0;i<n-1;i++)a[i]+=i;} mainf() {int i;struct S s{10,{2,3,1,6,8,7,5,4,10,9}}; if(s.a,s.n); for(i=0;i<s.n;i++)printf("%d",s.a[i]);} 程序运行后的输出结果是( )。
有以下程序 struct S { int n;int a[20];}; void f(int *a,int n) { int i; for(i=0;i<n-1;i++)a[i]+=i; } main() { int i;struct S s={10,{2,3,1,6,8,7,5,4,10,9}}; f(s.a,s.n); for(i=0;i<s.n;i++)printf("%d,",s.a[i]); } 程序运行后的输出结果是
有以下程序: #include void fun(char(*p)[6]) { int i; for(i=0;i<4;i++)printf("%c",p[i][i]); printf(" "); } main( ) { char s[6][6]={"ABCDE","abcde","12345","FGHIJ","fghij","54321"}; fun(s); } 程序的运行结果是( )。
有以下程序void fun(int *a,int i,int j){ int t;if (i
下列程序执行后的输出结果是 void funcl(int i); void func2(int i); char st[]="hello,friend!"; void funcl(int i) {printf("%c",st[i]); if(i<3){i+=2;func2(i);}} void func2(int i) { printf("%c",st[i]); if(i<3){i+=2;func1(i);}} main() {int i=
以下程序的输出结果是() #include int fun(intx){return++x;}void main(){ int i=0;while(fun(i)
下面程序段输出的i值是() #include void main() {int i;for(i=1;i=130)&(i*i
以下程序输出结果是 ______。 #include<iostream.h> void n(int i); void f2(int i); char st[]=”Howdoyoudo!”; void fl(int i){ cout<<st[i]; if(i<3){ i+=2: f2(i): } } void f2(int i) { cout<<st[i]; if(i<3) { i+=2; f1(i); } } void main() { int i=0; f1(i); }
下面程序输出的结果是( )。 #include<iostream> using namespace std; void main() { char ch[][8]={"good","better","best"}; for(int i=1;i<3;++i) { cout<<ch[i]<<endl; } }
有以下程序: #include 〈iostream〉 using namespace std; #define M 10 #define B4 void setstar(char *a, int n) { int i; for (i=0; i
有以下程序 #include <stdio.h> #include <string.h> void fun(char *s[],int n) { char *t; int i,j; for(i=0;i<n-1;++) for(j=i+1;j<n;j++) if(strlen(s[i])>strlen(s[j])) {t=s[i];s[i];s[j];s[j]=t;} } main() { char *ss[]={"bcc
相关题目
下面程序段的输出结果是( )。 class Base { int i; Base { add(1); } void add(int v) { i+=v: } void print { System.out.println(i); } } class Extension extends Base { Extension { add(2); } void add(int v) { i+=v*2: } } public class Test { public static void main(String args[]) { bogo(new Extension); } static void bogo(Base b) { add(8); print; } }
以下程序执行后sum的值是 void main() { int i , sum; for(i=1;i<10;i++) sum+="i;">
下列程序段的执行结果为( )。 #include<iostream> using namespace std; class example{ int n; public: example(int i){n=i;} void add(){s+=n;} static int s; void pr(){ cout<<s<<endl; } }; int example::s=0; int fuc(char *x); int main(){ example x(2),y(3),z(4); x. add(); y. add(); z.pr(); return 0; }
下面程序段的输出结果是( )。 class Base { int i; Base { add(1); } void add(int v) { i+=v: } void print { System.out.println(i); } } class Extension extends Base { Extension { add(2); } void add(int v) { i+=v*2: } } public class Test { public static void main(String args[]) { bogo(new Extension); } static void bogo(Base b) { add(8); print; } }
下面程序段的输出结果是 class Base { int i; Base() { add(1); } void add(int v) { i+=v; } void print() { System.out.println(i); } } class Extension extends Base { Extension() { add(2); } void add(int v) { i+=v*2; } } public class Test { public static void main(String args[]) { bogo(new Extension()); } static void bogo(Baseb){ b.add(8); b.print(); } }
2下面程序段的输出结果是( )。class Base{ int i; Base() { add(1); } void add(int v) { i+=v; } void print0 { System.out.println(i); }}class Extension extends Base{ Extension() { add(2); } void add(int v) { i+=v*2; }}public class Test{ public static void main(String args[]) { bogo(new Extension()); } static void bogo(Base b) { b.add(8); b.print(); }}
下面程序的输出结果是( )。 public class Sun { public static void main(String args[ ]) { int[] a=new int[11]; int[] p=new int[4]; int k=5; for (int i=1; i<=10; i++) a[i]=i; for(int i=1;i<=3;i++) p[i]=a[i*i]; for (int i=1; i<=3;i++) k=k+p [i]*2; System.out.println (k); } }
有以下程序: int m=1; void fun(int *n) { static int m=2; *n*=m-1; m+=2; } main() { int i; for(i=1;i<4;i++) { fun(&m); printf("%d",m); } } 程序的输出结果是( )
下列程序 void func1(int i); void func2(int i) char st[]="hello,friend!"; void funcl(int i) { printf("%c",st[i]); if(i<3){i+=2;func2(i);} } void func2(int i) { printf("%c",st[i]); if(i<3){i+=2;funcl(i);} } main() { int i=0;funcl(i);printf(" ");} 执行后的输出结果是( )
下列程序执行后的输出结果是( )。 void funcl(int i); void func2(int i); char st[]="hello,friend!"; void funcl(int i) { printf("%C",st[i]); if(i<3) { i+=2;func2(i); ) } void func2(int i) {printf("%c",st[i]); if(i<3) { i+=2;func1(i); } } main() {int i=0;funcl(i);printf(" "); )
下列程序执行后的输出结果是 void funcl(int i); void func2(int i); char st[]="hello,frlend!"; void funcl(int i) { cout<<st[i]; if(i<3){i+=2;func2(i);} } void func2(int i) { cout<<st[i]; if(i<3){i+=2;funcl(i);} } main() { int i=0; furicl(i); cout<<endl;}
下列程序执行后的输出结果是( )。 void funcl(int i); void func2(int i); char st[]="hello,friend!”; void funcl(int i) { printf("%c",st[i]); if(i<3){i+=2;func2(i);} } void func2(int i) { printf("%c",st[i]); if(i<3){i+=2;funcl(i);} } main() { int i=0;funcl(i);printf(" ");}
有以下程序 void fun(int *a,int i,int j) { int t; if (i<j) { t=a[i]; a[i]=a[j]; a[j]=t; i++; j--; fun(a,i, j); } ) main ( ) { int x[]={2,6,1,8},i; fun(x,0,3); for(i=0;i<4;i++) printf("%2d",x[i]); printf(""n); } 程序运行后的输出结果是
有以下程序 void fun(int*a,int i,int j) { int t; if(i<j) { t=a[i];a[i]=a[j];a[j]=t; i++; j--; fun(a,i,j); } } main() { int x[]={2,6,1,8},i; fun(x,0,3); for(i=0;i<4;i++) printf("%2d",x[i]); printf(" "); } 程序运行后的输出结果是
有以下程序: void fun(int *a,int i,int i) { int t; if(i<j) { t==a[i];a[i]=a[j];a[i]=t; i++; j--; fun(a,i,j); } } main() { int x[]={2,6,1,8),i; fun(x,0,3), for(i=0;i<4;i++) printf("%2d",x[i]); printf(" "); } 程序运行后的输出结果是( )。
有如下程序void func1(int st[],int i){ printf("%c",st[i]); if(i}void func2(int st[],int i){ printf("%c",st[i]); if(i}main(){ char st[ ]="hello,friend! "; int i=0;func1(st,i); printf("\n");}程序执行后输出的结果是A.hello B.hel C.hlo D.编译出错
下列程序执行后的输出结果是( )。 void func1 (int i); void func2(int i); char st[]="hello,friend!"; void func1 (int i) { printf("%c",st[i]); if(i<3){i+=2;func2(i);} } void func2(int i) { printf("%c",st[i]); if(i<3){i+=2;func1(i);}
下面程序执行后的结果是( )。 #include<iostream> using namespace std; void func1(int i); void func2(int i); char st[]="hello, friend!"; void func1(int i) { cout<<st[i]; if(i<3){i+=2;func2(i);} } void func2(int i) { cout<<st[i]; if(i<3){i+=2;func1(i);} } void main() { int i=0;func1(i);cout<<endl;}
下列程序执行后的输出结果是 void func1(int i); void func2(int i); char st[]="hello,friend!”; void func1(int i) { printf("%c",st[i]); if(i<3){i+=2;func2(i);}} void func2(int i) { printf("%c",st[i]); if(i<3){i+=2;func1(i);}} { int i=0;func1(i);printf(" ");}
有下列程序void func1(int i);void func2(int i);char st[ ]="hello,friend! ";void func1(int i){ printf("%c",st[i]); if(i<3){i+=2;func2(i);}}void func2(int i){ printf("%c",st[i]); if(i<3){i+=2;func1(i);}}main(){ int i=0;func1(i); printf("\n");}执行后的输出结果是A.hello B.helC.hlo D.hlm
广告位招租WX:84302438

免费的网站请分享给朋友吧