C + + Express-1

Source: Internet
Author: User

1. What are the steps to generate a C + + program?

Compile, pre-process, compile, link

2. What is the role of namespaces?

Namespaces are used to handle different code snippet name collisions.

3. How are namespaces used?

Method One: first put the declaration in the namespace (such as the declaration or definition of a namespace variable object member, function prototype, custom data type, etc.) into a header file, just as the header is used for various declarations. The declaration of the----namespace.

Then, through the # include file containing the namespace declaration of the file, and then within the namespace implementation of various definitions. ----the implementation of namespaces.

Method Two: You can even put the declaration and definition of the namespace together, at the time of Declaration, implement the definition of the member in the namespace. This is similar to the inline of a member function in a class.

4. How do I use Members in namespaces?

Method One: You can use the following directives. This means that all the members in the namespace are freed up, allowing the members in the namespace to have global scope. This will result in a possible re-introduction of the name conflict issue.

using namespace name space name;

Method Two: First declare after use. How many members are expected to be used, the command is passed anywhere in the source code file

Using name Space name:: member name; Declare the member you want to use, and refer to the member name directly below.

Method Three: Unify before each member name that is used

Namespace name:: The way a member name refers to a member in a namespace.

The latter two are more secure than the first method.


5. What is the error-prone data type summary?

float f=3.14f; Because the decimal is the double type by default, the description of the float variable should be displayed in the F suffix.

Double db=3.15; No problem

a long double ldb=3.24l; Capital L cannot save, C + + standard Specifies that the accuracy is at least less than double

Char ch= ' X '; Single-byte characters, not specifically described, are only ASCII characters that are signed and unsigned intersections.

char16_t ch=u ' X '; Double-byte characters, the prefix u cannot save

char32_t ch=u ' X '; Four byte characters, prefix u cannot save

wchar_t wch=l ' X ' wide-byte character, prefix L cannot save

BOOL Type: C does not have a type, C + + new data type. Range False (0), True (not 0)

C++11 added:

Auto automatic type deduction, which is automatically judged by the compiler.

Decltype (exp) automatic type deduction, determining type T based on the final type of expression

How does the 6.c++ type convert?

1) automatic type conversion: Suitable for conversions between assignment-compatible types. For example, the integer type of the real character type.

2) Forced type conversion:

Format one: (T) exp Whether the expression is a single or a polynomial, the variable or object that is closest to T is converted.

Format two: (t) (EXP) The entire expression is then converted to T-type

3)???? Strongly typed conversions:


7. Shift?

Logical shift: Refers to any number of binary modes that are generated by the shift after the vacancy, by 0 padding. For example, the left shift of C + +

Arithmetic shift: An empty space generated by any number of bits mode shifts, filled by a sign bit.

<< left shift operation: Regardless of the signed value (negative number) or unsigned value left shift always left, status 0;

>> Right Shift operation: Unsigned value right shift is still a logical shift, right to lose, high fill 0, and negative right shift, high vacancy 1

Summary: 1) The left shift of non-negative numbers is a logical shift, the missing vacancy is 0, the left shift of the negative is also vacant by 0 padding, while the right shift high 1

2) for signed values (negative numbers), the shift loses cross-platform portability, and for all function interfaces that involve shift operations, you should use a non-

The parameters of the symbol. unsigned int ...


8. Enum type?










C + + Express-1

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.