//difference ⑦: Three mesh operator (c + + version)#include <iostream>using namespacestd;//three mesh operator C returns the value of a variable the C + + language is the return variable itselfvoidMain () {intA =Ten; intb = -; A< b? A:B = -; //the three-mesh operator in C + + can return directly to the variable itself, so it can appear anywhere in the program//Note://if one of the values returned by the three-mesh operator is a constant value, it cannot be used as an lvalue//(A < b? 1:b) =;System"Pause");}
//difference ⑦: Three mesh operator (C language version)#include <stdio.h>#include<stdlib.h>#include<string.h>voidMain () {intA =Ten; intb = -; //a < b? a:b = 30; Error C2106: "=": Left operand must be left value//in the C language, a < b? A:b The value returned here is a, not a variable//constants are not allowed to do the left value.//The Lvalue is important in C + +, where the condition of the left value is that the element must have memory space (the value in the register has no memory space)/////Implement the three-mesh operator in C to return the variable * (a < b? &a: &b) =; System ("Pause");}
C + + C + + C language differences Third speaking