zoukankan      html  css  js  c++  java
  • c++返回引用

    #include <iostream>
    #include <ctime>
     
    using namespace std;
     
    double vals[] = {10.1, 12.6, 33.1, 24.1, 50.0};
     
    double[]& setValues( int i ) {
       return vals;   // return a reference to the ith element
    }
     
    // main function to call above defined function.
    int main () {
     
       cout << "Value before change" << endl;
       for ( int i = 0; i < 5; i++ ) {
          cout << "vals[" << i << "] = ";
          cout << vals[i] << endl;
       }
     
       setValues(1)[1] = 20.23; // change 2nd element
       setValues(3)[2] = 70.8;  // change 4th element
     
       cout << "Value after change" << endl;
       for ( int i = 0; i < 5; i++ ) {
          cout << "vals[" << i << "] = ";
          cout << vals[i] << endl;
       }
       return 0;
    }
    MySQL限时解答,24小时内友哥专业解答
    http://www.yougemysqldba.com
    如有进一步需要请联系微信onesoft007
    微博账号@友哥一指
  • 相关阅读:
    [ARC080D] Prime Flip
    硬币游戏
    点分治
    OneInDark对众数的爱
    [CF838D] Airplane Arrangements
    网络流总结(转载)
    二分图最大权完美匹配(KM)
    网络流
    FWT
    FFT & NTT
  • 原文地址:https://www.cnblogs.com/youge-OneSQL/p/9450290.html
Copyright © 2011-2022 走看看