C ++ Primer Study Notes 1

Source: Internet
Author: User



Void is also a type. It is often used in the return field of the function whose return value is void.


C ++ only specifies the minimum storage space of various basic built-in types, and does not limit its upper limit. For int, most compilers use a larger space than required, generally 32 bits. However, the minimum size is 16 bits.


In C ++, there is no limit on the minimum storage space of the bool type. The bool variable in C ++ may not occupy the memory space, and the language implementation is macro definition, two values, true and false, are defined.


Short, int minimum 16 bits; long minimum 32 bits


The Float type can only represent 6 Valid digits, which may result in loss of precision During computation and is not suitable for floating point computation. Double represents a 10-bit valid number and is suitable for floating-point operations. The key is that the double operation costs are equal to the float. The extra part is negligible.


In general compiler implementation, short occupies half the length (a 32-bit machine with four characters in length, that is, a word), int Is a word length, long is one or two characters long (in 32-bit machines, both long and int are usually one character long ).


Any value of the arithmetic type (whether integer or floating point type, whether positive or negative or 0) can be assigned to a bool type variable. The principle is that 0 indicates false, the other non-0 values are true.


Integer indicates whether there are symbols or symbols, and the keyword is unsigned.


It is valid to assign a negative number to an unsigned integer in C ++, but the value stored in the variable is the value after the modulus.


The floating point number is different from the number of points represented by an integer. The point is the decimal point in the real number. In general, float uses one word (32 bits), double uses two words (64 bits), and long double uses three or four words (96bits or 128 bits ). The value range of the type determines the number of valid digits that can be expressed by a floating point number.


In integer operations, although the precision of the long type is higher than that of the int type, the operation cost increases greatly.


The literal value constant is called the literal value because it can only be called by its value. The constant is because it cannot be modified. Each literal value has a corresponding type, but all of them are constants. Only the basic built-in type has a literal constant, and the class type does not have a literal constant.


The nominal value starting with 0 (0) indicates an octal number, and the nominal value starting with 0x or 0X indicates a hexadecimal number. The default type of the integer literal value is int or long. If the value is in the int value range, it is int. If the value exceeds the int value, it is long.


You can add u or U after the nominal value to change the nominal value to unsigned. Similarly, l or L variable growth type is added.


The default floating point literal value is double, unless f or F is explicitly indicated after the floating point is displayed.


The nominal values of the Bool type are true and false.


The front or back of the string literal value can be l or L to be a wide character.


When a string literal is connected to a wide string literal, undefined behavior occurs.


A backslash (\) must be used to separate the character faces of a multi-line string. However, the backslash must be the last character of the line and cannot be followed by comments or spaces, any character of the next row is considered as a string component, so there is no normal indentation of the next row. (This is similar to using a macro definition to represent a function that spans multiple rows)


The left and right values can be used as the value assignment operator (equal sign "="). The left is the right value and the right is the right value. The depth of the Left value is the variable with memory space. For example, I ++ is not the left value, and ++ I is the left value.


Initialization can be divided into two types: Direct initialization and value initialization, int value = 11; this is the replication initialization that is often used in the early stages of learning. Its direct initialization indicates int value (11). The two built-in types are basically the same, but there is a big difference between them for class objects. For details about object initialization, see the csdn blog.


For the differences between the description and definition, see the csdn blog. The essence of defining variables is to open up space. In a program, a variable can have only one and only one definition. Declarations declare variables without definition through the extern keyword. In a program, a variable can be declared multiple times.

Extern int value; is a standard declarative type. But extern int value = 11; this is the definition.


Scope of variables: global scope, Class scope, namespace scope, local scope, block scope, and bracket scope.


The global variables are extern by default and can be accessed by external files. After the const is added, local variables of the cost file are forced and cannot be accessed by external files. That is why the const global variables can be defined in the header file. To make it global, extern is required.


The header file is generally not used for definition. There are three exceptions: class definition, inline function, and const variable.


A reference is a composite type. A composite type means that the definition of this type requires other types and cannot define references of the reference type, however, any reference of other types can be defined (the array itself can be referenced, but its element type cannot be referenced because it cannot be initialized ).

Int & value = 11; is incorrect; but const int & value = 11; this is OK.


Double dval = 3.14; const int & ri = dval; this cross-type reference is acceptable. The compiler performs a type conversion in the implementation process, with int tempint = dval; const int & ri = tempint in the middle;

Summary: Non-const references can only be bound to objects of the same type. const references can be bound to objects of different types or right values.


Each defined enumeration is a type. enumeration is considered as a compiler constant, and the enumerated Member values can be unique.


The constant folding principle of the string literal value: assign the same string literal value to multiple variables. These variables have the same address. In practice, const and define have one effect, no storage space is used to store the const variable.


Zookeeper

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.