/**
* a
* 返回类型不匹配
* int 改为 string
*
* b
* 没有返回类型 加 void
*
* c
* 形参同名 v1 改 v2
*
* d
* 函数体没有花括号 { }
*/
6.3
#include<iostream>using std::cout;using std::endl;intfact(int val){
int ret =1;while(val)
ret *= val--;return ret;}intmain(){
cout <<fact(5)<< endl;return0;}
6.4
#include<iostream>using std::cout;using std::endl;using std::cin;intfact(){
int val;int ret =1;
cin >> val;if(val >0)while(val)
ret *= val--;elseif(val <0)while(val)
ret *= val++;elsereturn0;return ret;}intmain(){
cout <<fact()<< endl;return0;}
#include<iostream>usingnamespace std;// 初始化一个非引用的变量时, 初始值被拷贝给变量voidfunc(int*x,int*y);intmain(){
int n =10, m =20;func(&n,&m);
cout << n <<" "<< m << endl;return0;}voidfunc(int*x,int*y){
int p =*x;*x =*y;*y = p;}
6.11
#include<iostream>usingnamespace std;voidreset(int&x);intmain(){
int x =30;reset(x);
cout << x