The first chapter of accelerated C + + Practice

Source: Internet
Author: User

(Test environment is WINDOWS8 under vs2013)

1-1 is the following definition correct? Why?

1-2 is the following definition correct? If not, why?

A: The compilation result of vs2013, 1-1 is correct, 1-2 is wrong, the wrong hint

Usage of "+":

First + can only connect two string types or a string type and a direct amount of strings, followed by a left-associative.

So the first one is OK, because Hello is a string type, with "world" after the combination of string type, followed by "! "Combined

And the second one is wrong, because "hello" and "world" are the direct amounts of strings.

1-3 are the following procedures correct? If it's right, what does it do? If not, why?

Let's look at the results of the operation:

There is no problem with running the result, so the program is correct because "{}" is a living space and the first S is released after the first curly brace ends

1-4 are the following programs right? What happens if we change the last third line} to};

After rewriting:

The result of the operation is the same, or curly braces for the existence of space problems, as well as the role of semicolons, but added an empty statement

1-5 are the following procedures correct? If it's right, what does it do? If not, say the reason and rewrite it correctly.

After compilation

Yes, because X is in the third bracket, so there is no X in the second layer, and to output X, you have to put them in the same living space.

It's like this:

Since S is defined in the second bracket, if there is no new definition of s in the third layer, then S is defined by the second layer, which is less of a rewrite, and allows all of them to be in a living space:

1-6 when the following program asks you to enter, you enter two names (for example, Samuel Beckett). How will it handle it? Predict the results before running the program and try again.

is a variable name is assigned two times to print separately, the result

The first chapter of accelerated C + + Practice

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.