有时候函数原本不需要返回值,但为了增加灵活性如支持链式表达 , 可以附加返回值。
1 #include <iostream> 2 #include <stdlib.h> 3 #include <math.h> 4 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 5 using namespace std; 6 int main(int argc, char** argv) { 7 double y; 8 for(double x=-5;x<=5;x++){ 9 y=exp(x); 10 cout<<"exp("<<x<<")="<<y<<endl; 11 } 12 }