C++编程测试题:程序输出与函数计算.pdfVIP

  • 0
  • 0
  • 约1.14万字
  • 约 14页
  • 2026-02-12 发布于北京
  • 举报

C++编程测试题:程序输出与函数计算.pdf

•1该程序的输出为:(a)3(b)5(c)0

•#includesetjmp.h

_

•staticjmpbufbuf;

•intmain(){

•volatileintb;

•b;

=3

•if(setjmp(buf)!){

=0

•printf(%d,b);

•exit(0);

•}

•b;

=5

•longjmp(buf,1);

•return0;

•}

•2该程序的输出为:(a)3(b)5(c)6(d)7

•structnode{inta;intb;intc;};

•intmain(){

•structnodes={3,5,6};

•structnode*pt=s;

•printf(%d,*(int*)pt);

•return0;

•}

•3这段代码计算的是关于x和n的什么函数?

•(a)x^n(b)x*n(c)n^x(d)以上都不是

•intfoo(intx,intn){

•intval;

•val=1;

•如果(n){

0

•如果(n%2==1)值=值*x;

•val=val*foo(x*x,n/2);

•}

•returnval;

•}

•4该程序的输出为:(a)22(b)21(c)25(d)以上都不是

•1,Theoutputforthisprogramis:(a)3(b)5(c)0

•#includesetjmp.h

•staticjmp_bufbuf;

•intmain(){

•volatileintb;

•b=3;

•if(setjmp(buf)!=0){

•printf(%d,b);

•exit(0);

•}

•b=5;

•longjmp(buf,1);

•return0;

•}

•2,Theoutputforthisprogramis:(a)3(b)5(c)6(d)7

•structnode{inta;intb;intc;};

•intmain(){

•structnodes={3,5,6};

•structnode*pt=s;

•printf(%d,*(int*)pt);

•return0;

•}

•3,Whatfunctionofxandniscomputebythiscodesegment?

•(a)x^n(b)x*n(c)n^x(d)Noneoftheabove

•intfoo(intx,intn){

•intval;

•val=1;

•if(n0){

•if(n%2==1)val=val*x;

•val=val*foo(x*x,n/2);

•}

•returnval;

•}

•4,Theoutputforthisprogramis:(a)22(b)21(

文档评论(0)

1亿VIP精品文档

相关文档