小编AEG*_*GIS的帖子

c ++嵌套条件运算符循环

我很好奇c ++如何处理这个嵌套的条件运算符.我很确定我理解它是如何工作的,但我很好奇,任何人都可以通过图解释循环如何执行嵌套的条件运算符.

例如,循环是否会为每个实例执行每个条件运算符的第一个表达式?

这个嵌套的条件运算符也是这样构造的:

(i <2)?x [i]:y;

!一世 ?y:x [1];

我想我对这个性质非常好奇.除非你能够给我一个关于循环如何执行这个条件运算符的充分解释,否则请不要回答.

#include "stdafx.h"
#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])

{
const char x[2] [20] = {" Cloud "," at your service\n"}; 
const char * y = "Strife"; 
for (int i = 0; i < 7; i++) 
    cout << (( i < 2)? !i ? x [i] : y : x[1]);

cout << endl << endl << x[0] << endl << x[1] << endl;

cin.get(); …
Run Code Online (Sandbox Code Playgroud)

c++ conditional loops nested operator-keyword

0
推荐指数
1
解决办法
2592
查看次数

标签 统计

c++ ×1

conditional ×1

loops ×1

nested ×1

operator-keyword ×1