Review of basic knowledge of C + + (I.)

Source: Internet
Author: User
Tags arithmetic operators bitwise operators modifier modifiers

Data types, constants and variable parts: (find some points that have been discovered for the first time in so many years)

What are the C + + basic data types:

Answer: Integral type, floating point type, void type.

Note: All other data types are extensions of these three types, and void types are often used in actual programs to indicate that pointers are untyped, pointing to the entire block of memory, and that the program can parse itself as needed.

2. Classification and difference of integral type:

A: The data types that represent integers, characters, and Booleans are collectively called reshaping. It can be divided into 13 categories according to the different length modifier words and the symbol modifiers. Short and short modifier: short half machine word length, int a machine length, long two machine length. Symbol modifiers: Signed, unsigned unsigned, distinguished from the representation range. Char, unsigned char, signed char, int, unsigned int, signed int, short int, unsigned short int, signed short int, long int , unsigned long int, signed long int, BOOL.

Note: It is not important to specify a few bytes for each data type, because it is determined by the platform, and it is a wise choice to remember the machine word length.

3. Briefly describe the constants in C + +:

A: Constant constants are used to identify, measure, and compare values that are determined before the program is run and will not change during operation. Can be divided into:
Shaping Constants : Note that the shape constant can be specified in the system, before the constant if there is 0x, then 16, if there are 0 is eight binary. You can have suffix symbols, not case-sensitive, L represents long shaping, and U is unsigned.
floating-point constants : Note that the floating-point type is only decimal, the default is double, the absolute value is less than 1 o'clock before the decimal point of 0 can be omitted, float indicates that the range is +-e38,double in +-e308, the suffix is also not case-sensitive, f is a symbol, and L represents a long double precision.
character Constants : ASCII is used to represent a character, and a single quote and backslash is used to denote an escape character, such as ' \x2f ' for hexadecimal 2f.
string Constants : characters enclosed in double quotation marks.
Escape character constant:\ n line break \ r Enter
Address constants

Note: For example, qrep version information, different versions of the version number is written dead.

4. The difference between a constant and a variable:

A: Constants must be initialized when defined, and the value is immutable, the constant is not addressable, its address is not allowed to be assigned to a non-const pointer, and the variable can be addressed. Constant compilation execution is highly efficient.

5. What are the operators:

A: operator, also known as the operators, by the operand is divided into unary operators, two-ary operators and ternary operators. The functions are divided into arithmetic operators, relational operators, logical operators, bitwise operators, assignment operators, increment and decrement operators, arrow operators, condition operators, sizeof operators, and comma operators.

Note: The value of the comma expression is the value and type of the last expression. However, when evaluating, the values of the expressions are computed in the left-to-right order, respectively.

6. Precedence of the operator:

A: A total of 16 levels, in general, the monocular is higher than the number of eyes, arithmetic is higher than logic. Three right-to-left combinations, a single-mesh operator, a conditional operator, and an assignment operator.

7. What is the difference between a pointer's self-increment and decrement:

A: The pointer's self-increment, refers to the point of increase or decrease of the address. Like Char *p=&str[0];. ++p is to point the pointer to str[1], ++*p is the data in str[0] plus 1, for example, originally C, add to D.

8. What are the initialization methods of variables?

Answer: Two, assignment initialization and direct initialization. Direct initialization is more efficient.

9. What are the differences between declarations and definitions?

A: The declaration primarily indicates the name and type, and the definition specifically allocates space. The Declaration and implementation of a function is more common, and the declaration of a variable is seen in duplicate definitions or global variables.

Scope in C + +?

A: Scopes are divided into global scopes, local scopes, and statement scopes. Scopes can be nested,

11. What are the storage types of variables?

A: The storage type of a variable determines its life cycle, and the descriptor for the storage type is 4, auto,register,static, and extern.
Auto and register are called automatic storage types , auto is the default, and the life cycle begins at the execution of the block, ending at the end of the block. In the stack, the execution end is automatically released, with the lifetime and scope consistent. Register variables are not recommended because the compiler is mostly optimized.
statically static storage type , stored in the global data area, such as not showing initialization, the system will automatically assign a value of 0, and initialize only once, with the global life cycle, according to the defined location, divided into local static variables and global static variables, also known as internal static variables and external static variables.
extern external storage variables , global variables and functions in the program are external by default, and other programs can use them through extern declarations.

12. What are the storage areas of the program, and what are their characteristics?

A: The storage area of the program includes code area, static data area, stack area and heap area, the corresponding life cycle is divided into static life period, local life period and dynamic life period.
Data in a static data region has a static lifetime, global variables, static global variables, and static local variables all exist in the static data area. The system initializes it automatically, and the function resides in the code area, which also has a static lifetime.
The data in the stack area has a local lifetime, if not initialized, the values are random, one thing to note is that static local variables have local scope but have a static life cycle.
The heap has a dynamic life cycle, mainly through new and delete to deal with memory, but also argues that the single proposed to have a free storage area, by malloc and freedom operations.

Note: This section relates to memory, put address: http://wenku.baidu.com/view/1ecb5321482fb4daa58d4b91.html

13. What is a reference?

A: The reference is another name of the object, defined by the & symbol, such as int i=0; int &ref=i; There are two purposes for quoting : The first is to improve performance, the use of references does not result in the copying of objects, "custom Class &" Here is the purpose, but if you do not want the function to modify this parameter, it is best to precede the Const. The second is to be able to modify the object. Here the "IStream &" is the purpose, as a parameter, if you do not pass in the reference , then the stream is a formal parameter, the function of modifying this parameter will not cause the change of the function outside the variable, obviously not. Be aware, however, that the original object of the const reference is also Const.

Syntax section:

While,do while: Easy to forget, there is a semicolon behind the do and.

15. In a switch statement, you can define a variable only after the last case or default.

16. Recursion is divided into boundary conditions, recursive forward segment and recursive return segment three parts. Recursive forward when the boundary condition is not satisfied, and returns recursively when it is satisfied.

17. Hanoi Tower problem: Can be solved by recursive and non-recursive, note that three pillars do not use the order of the limit, non-recursive can be used to simulate the process of the stack, the key is to divide the number of plates larger than 1 into 1 of the resolution steps.

Input and Output section:

18. Note that C + + itself does not provide input and output operations, which are provided by the standard library.

19. Classification of several IO:
Standard I/O: operation on standard input
File I/O: input and output of files on external storage disk
String I/O: input and output to the in-memory string storage space

20. Various I/O classes: base class iOS
The four major classes are derived directly: input stream istream, output stream ostream, file stream fstreambase and string stream strstreambase.
Input file Stream class Ifstream, output file stream class Ofstream
Input string Stream class Istrstream, output string stream class Ostrstream
more centralized : Input output stream class iostream, input output file stream class FStream, input output string stream class Strstream.
Iostream standard class Library, with this is enough.

21. The purpose and method of the overloaded input and output:

A: Overloads provide more than one definition for the same function name in the same scope, and the delegate compiler invokes the selection to provide more concise code.
ostream& operator<< (ostream &out, const classname &object) {out<<...; return out;}
The input stream changes ostream to IStream.

22. How to read a file:

Answer: #include <fstream> fstream openfile (filepath); Openfile.eof (); Openfile.fail (); Openfile.close (); Use Cin,get or getline to read characters. You can use Ofstream,.open when writing,. Close. . Clear. The << operator can be used to write.

Review of basic knowledge of C + + (I.)

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.