c++作業:輸入兩個整數,用函數求兩數之和。函數外部聲明有什么作用?


#include <iostream>
using namespace std;
  
int main(){
      //求兩數的和? 
      
 
    int a,b,s;
        cout<<"請你輸入兩個整型的數字:"<<endl;
    cin>>a>>b;
     int sum(int x ,int y);
     s=sum(a,b);//實際參數 ,代表具體數值,在()當中 
     cout<<"The sum of a and b is:"<<sum<<endl;
     //system("pause");
     return 0;
 }
 //首先確定函數是否需要返回值?需要返回值的話要寫返回值類型 如果不需要返回值則寫void 
 int sum(int x ,int y){//形式參數 //變量的生命周期 接收實際參數的賦值 int x=a,int y=b; 
     return x+y;
 }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM