Conditionals with Omitted Operands

The middle operand in a conditional expression may be omitted. Thenif the first operand is nonzero, its value is the value of the conditionalexpression.

Therefore, the expression

     x ?

: y

has the value of x if that is nonzero; otherwise, the value of
y.

This example is perfectly equivalent to

     x ? x : y

In this simple case, the ability to omit the middle operand is not especially useful. When it becomes useful is when the first operand does,or may (if it is a macro argument), contain a side effect. Then repeating the operand in the middle would perform
the side effect twice. Omitting the middle operand uses the value already computed without the undesirable effects of recomputing it.

x? : y is equal to x?

x:y

Conditionals with Omitted Operands (x ? : y)的更多相关文章

  1. C#解析字符串公式

    /// <summary> /// 中缀表达式到逆波兰表达式的转换及求值 /// </summary> public class RpnExpression { #region ...

  2. ThinkPHP 汉字转成多种形式拼音

    模型: <?php namespace Admin\Model; use Think\Model; /** * 汉字转拼音 * @author huangguojin */ class ZHMo ...

  3. Conditionals

    1. Modulus operator (%) The modulus operator works on integers and yields the remainder when the fir ...

  4. 【iOS】swift-Binary operator '|' cannot be applied to two UIViewAutoresizing operands

    let view = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 568)) addSubview(view) view.autoresi ...

  5. Learn X in Y minutes Where X=c++

    http://learnxinyminutes.com/docs/c++/ C++ is a systems programming language that, according to its i ...

  6. 萌新笔记——vim命令“=”、“d”、“y”的用法(结合光标移动命令,一些场合会非常方便)

    vim有许多命令,网上搜有一堆贴子.文章列举出各种功能的命令. 对于"="."d"."y",我在无意中发现了它们所具有的相同的一些用法,先举 ...

  7. Android立体旋转动画实现与封装(支持以X、Y、Z三个轴为轴心旋转)

    本文主要介绍Android立体旋转动画,或者3D旋转,下图是我自己实现的一个界面 立体旋转分为以下三种: 1. 以X轴为轴心旋转 2. 以Y轴为轴心旋转 3. 以Z轴为轴心旋转--这种等价于andro ...

  8. $x^2+y^2=c^2$

    $x^2+y^2=c^2$ 每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis. 每一 ...

  9. android3D动画,绕y轴旋转

    原文地址:http://blog.csdn.net/x_i_a_o_h_a_i/article/details/40449847 其实网上的3D旋转的例子很多,在这里我只是想把其代码做一个解释. 先上 ...

随机推荐

  1. C语言-02基本运算

    1.除法运算 / 整数除于整数,还是整数.参与运算的操作数必须是同类型. 1/2的值是0.参与运算的操作数是什么类型,得出的值就是什么类型.   10.5 + 10将右边的10提升为了double类型 ...

  2. POJ 2442 Sequence 优先队列

    题目: http://poj.org/problem?id=2442 #include <stdio.h> #include <string.h> #include <q ...

  3. 隐藏 Status Bar

    iOS6和iOS7在隐藏 Status Bar 三种方式比较: Storyboard 界面上选中UIViewController,最右边Simulated Metrics找到 Status Bar 设 ...

  4. 传感器- 加速计 - CoreMotion

    /** *  CoreMotion * */ #import "ViewController.h" #import <CoreMotion/CoreMotion.h> ...

  5. php实例-正则获取网站音频地址的实例(Listen to this 1)

    主要用到了:file_get_contents();preg_match_all(); 这2个函数 查看地址:http://git.oschina.net/xiaoz6/phpExample

  6. [BZOJ 3531] [Sdoi2014] 旅行 【离线+LCT】

    题目链接:BZOJ - 3531 题目分析 题目询问一条路径上的信息时,每次询问有某种特定的文化的点. 每个点的文化就相当于一种颜色,每次询问一条路径上某种颜色的点的信息. 可以使用离线算法, 类似于 ...

  7. Class类文件结构、类加载机制以及字节码执行

    一.Class类文件结构 Class类文件严格按照顺序紧凑的排列,由无符号数和表构成,表是由多个无符号数或其他数据项构成的符合数据结构. Class类文件格式按如下顺序排列:   类型 名称 数量 u ...

  8. linux使用ps1设置命令行提示符

    要自定义命令行提示,需要ps1来设置.完成自定义需要以下几个步骤: 1.编辑~/.bashrc文件 vi ~/.bashrc 2.在.bashrc文件中添加以下一行自定义内容 export PS1=& ...

  9. 【HDOJ】2853 Assignment

    最小费用最大流可解最优解.至于dif如何解,可以把w扩大100倍,如果mission编号和排列P相等则对w+1,然后建立网络流.对结果取模100可以得到没有改变mission的company数目,用c ...

  10. wcf异常汇总

    1.确保客户端可以接收到服务端的异常 2.部署wcf出错,http错误404.3 3.无法自动调试 未能调试远程过程.这通常说明未在服务器上启用调试 WCF 托管在IIS上 4.ChannelFact ...