关于c++:C39逗号操作符的分析

11次阅读

共计 400 个字符,预计需要花费 1 分钟才能阅读完成。

逗号操作符

逗号操作符 (,) 能够形成逗号表达式

逗号表达式用于将多个子表达式连贯为一个表达式

逗号表达式的值为最初一个表达式的值

逗号表达式中的前 N - 1 个子表达式能够没有发返回值

逗号表达式依照从左向右的程序计算每个子表达式的值

#include <iostream>
#include <string>

using namespace std;

void func(int i)
{cout << "func() : i =" << i << endl;
}

int main()
{int a[3][3] = {(0, 1, 2),
        (3, 4, 5),
        (6, 7, 8)
    };
    
    int i = 0;
    int j = 0;
    
    while(i < 5)    
        func(i),
    
    i++;
        
    for(i=0; i<3; i++)
    {for(j=0; j<3; j++)
        {cout << a[i][j] << endl;
        }
    }
    
    (i, j) = 6;
    
    cout << "i =" << i << endl;
    cout << "j =" << j << endl;

    return 0;
}
正文完
 0