zoukankan      html  css  js  c++  java
  • c++ 函数的引用传递和按值传递

    #include <iostream>
    #include <cstring>
    //#define BYTE char

    //传递引用
    void swapr(int & a,int & b);

    //传递指针
    void swapp(int * a,int * b);

    //按值传递
    void swapv(int a,int b);

        int main()  
        {    
            using namespace std;
            int a=3,b=4;
            swapr(a,b);
            cout <<a <<"|" <<b<<endl;
            swapp(&a,&b);
            cout <<a <<"|" <<b<<endl;
            swapv(a,b);
            cout <<a <<"|" <<b<<endl;
        }
        void swapr(int & a,int & b)
        {
            int temp=a;
             a=b;
             b= temp;
        }
        void swapp(int * a,int * b)
        {
            int temp =*a;
            *a=*b;
            *b=temp;
        }
        void swapv(int a,int b)
        {
            int temp=a;
            a=b;
            b=temp;
        }

    /*------------------demo 2---------------------------------*/

    double swapr(double a);
    double swapp(double &a);
     using namespace std;
        int main()  
        {    
            
            double a=3.0;
            cout <<swapr(a) <<endl;
            cout << a <<endl;
            cout <<swapp(a)<<endl;
            cout << a <<endl;
        }
        
        double swapr(double a)
        {
            a *=a*a;
            return a;
        }
        
        double swapp(double &ra)
        {  
            ra *=ra*ra;
            return ra;
        }

  • 相关阅读:
    poj 3122 Pie (二分)
    poj 1905 Expanding Rods(二分)
    poj 3258 River Hopscotch (二分)
    poj 3273 Monthly Expense(二分穷举)
    最小最大堆
    最小—最大堆
    zend studio 9 字体,颜色,快捷键等相关设置
    javascript onbeforeunload
    php DOMDocument 不能解析引用外部DTD的XML
    phpdoc 注释关键字含义
  • 原文地址:https://www.cnblogs.com/wyxy2005/p/2845806.html
Copyright © 2011-2022 走看看