Exercises for C ++ Primer version 4 and exercises 1.6

Source: Internet
Author: User

Exercises for C ++ Primer version 4 and exercises 1.6

Note: This essay is directly copied in C ++ Primer (Fourth Edition) exercise solution (full version. This is mainly for me to read it again and again later.

Exercise 1.6

Explain the following sections:

1 std: cout <"The sum of" <v1; 2 <"and" <v2; 3 <"is" <v1 + v124 <std: endl; 5


Is this code legal? If it is legal, why, if it is illegal, why?

[Answer]

This code is invalid.

Note that there are semicolons at the end of lines 1st, 2, and 4, indicating that the Code contains three statements, that is, lines 1st and 2 constitute one statement, and lines 3rd and 4 constitute one statement. "<" Is a binary operator. In statements 2nd and 3, the first "<" lacks the left operand, so it is invalid.

Add "std: cout" at the beginning of lines 2nd and 3 to correct the error.

1 std: cout <"The sum of" <v1; 2 std: cout <"and" <v2; 3 std :: cout <"is" <v1 + v124 <std: endl;

 

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.