C + + C + + C language differences Third speaking

Source: Internet
Author: User

//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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.