如果函数的返回值是一个对象,有些场合用“引用传递”替换“值传 递”可以提高效率。而有些场合只能用“值传递”而不能用“引用传递”,否则会出 错。

 

 1 #include <iostream>
 2 #include <math.h>
 3 #include <stdlib.h>
 4 //main()函数的定义
 5 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 6 using namespace std;
 7 int main(int argc, char** argv) {
 8     double y;
 9     int N;
10     //输入一个大于等于0的数
11     do {
12         cout<<"N=";
13         cin>>N;
14         if (N>=0) break;
15     } while (1);
16 
17     //计算并显示
18     for(int i=0;i<=N;i++){
19         y=pow(2,i);
20         cout<<"pow("<<2<<","<<i<<")="<<y<<endl;
21     }
22     return 0;
23 }

 

相关文章:

  • 2021-12-23
  • 2022-01-11
猜你喜欢
  • 2021-07-20
  • 2021-04-11
  • 2021-12-17
  • 2021-12-05
  • 2021-11-09
  • 2022-12-23
相关资源
相似解决方案