写出程序的运行结果

写出程序的运行结果,第1张

printf("%d,%s\n",--i,p++)

输出--i为4这很容易;p是指针,本圆贺没身的值是一个地址

*p=s+3  //p指向数组s的第四项

p++  //p变为指向数组s的第五项

p -i  //此时 i=4,p -i即p -4,所以p -4指向拍启数橘纳组s的第一项

printf("%s\n",p-i)  // %s 所以从数组s的第一项开始输出整个字符数组

第一个程序

10 0.23

XThis is a test

程盯运序有误,修改后运行结果如上。

修改后的程序如下:

#include <iostream.h>

template <class Type1,class Type2>

class myclass{

public:

myclass(Type1 a,Type2 b) 不能加“.”

{

i=aj=b

}

void show()

{

cout<<i<<" "<<j<<endl空蠢败格用" "换行用endl

}

private:

Type1 i

Type2 j

}

int main()

{

myclass <int,double>ob1(10,0.23)

myclass <char,char* >ob2('X',"This is a test") 用英文引号! 例如" " ' ' 不能用中文

ob1.show()

ob2.show()

return 0

}

第二个程序

4!=24

n=-2 不能计算n!

程序执行结束

程序有误,修改后结果如上,程序如下:

#include <iostream.h>

int f(int )

int main()

{

try

{

cout<<"4!="<<f(4)<<endl 要用英文标点符号

cout<<"-2!="<<f(-2)<<endl要用英文标点符号

}

catch(int n)

{

cout<<"n="<<n<<"不能计算n! "<凯档梁<endl 要用英文标点符号

cout<<"程序执行结束。"<<endl 要用英文标点符号

}

return 0

}

int f(int n)

{

if(n<=0)

throw n

int s=1

for(int i=1i<=ni++)

s*=iI 改为 i

return s

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/12464407.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-23
下一篇2023-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存