Detailed explanation of C++ keywords

There are 73 keywords in C++11 .

 

  • volatile:类型修饰符type specifier,和 const 对应,A volatile specifier is a hint to a compiler that an object may change its value in ways not specified by the language so that aggressive optimizations must be avoided.   

volatile int i=0;a=i;b=i;

Volatile points out that i is subject to change at any time, and it must be read from the address of i every time it is used, so the assembly code generated by the compiler will re-read the data from the address of i and put it in b. The optimization method is that since the compiler finds that the code between the two reads of data from i has not operated on i, it will automatically put the last read data in b. Instead of re-reading from i. In this way, if i is a register variable or represents a port data, it is prone to errors, so volatile can guarantee stable access to a special address.

  • nullptr: C11 null pointer, https://www.cnblogs.com/DswCnblog/p/5629073.html

  • auto: The keyword automatically infers the data type of the variable based on the initial value. In the C++98/03 standard, auto indicates the automatic storage type [6]; in the C++11 standard, auto indicates that the compiler statically determines the type it should have.
  • bool,true,false

  • break, continue, goto: break is used to jump out of a for or while loop or switch. continue is used to jump to the beginning of the loop. goto is used to unconditionally jump to a label inside a function.

  • case,default,switch :

  • catch, throw, try: exception handling, try specifies the start of the try block, and the catch after the try block can catch the exception. Exceptions are thrown by throw. throw also represents the dynamic exception specification in functions, but was marked obsolete in C++11 (replaced by the noexcept section).

  • const,volatile 

  • struct, class, union: used for type declaration. class is a generic class type. Struct is a special class type in C++, and only the default implicit member and base class access qualifications in the declaration are different from class (struct is public, class is private). union is a union type

  • delete,new

    delete is used alone to release objects with dynamic period, the default version calls the global deallocator (deallocator)::operator delete and destructor. new is used alone to indicate a request to allocate a dynamic storage duration object. The default version calls the global allocator::operator new and the specified destructor. When used in conjunction with operator, it means operator delete and operator new respectively, which are used to release the memory of the allocator and allocate memory. operator delete is also called when allocating memory is interrupted by an exception.

  • enum: The keywords that make up the enumeration type name. C++11 adds scoped enumerations, declared with enum class or enum struct (both equivalent)

  • explicit

  • friend: Declare a friend so that it is not restricted by access control. Friend function refers to some functions that can access all members of a class although they are not class member functions; friend class: All member functions of a friend class are friend functions of another class, and can access all members of another class. (1) Friend relationships cannot be inherited. (2) Friendship is one-way and not commutative. (3) Friend relationship is not transitive; friend member function

  • inline: prompt compile-time inlining - embed the called code into the calling function. In order to solve the problem that some frequently called small functions consume a lot of stack space (stack memory), the stack space refers to the memory space where the local data of the program (that is, the data in the function) is placed.

  • noexcept In C++11, the keyword noexcept is used to declare a function that cannot throw any exceptions.

C/C++ preprocessing directives #define, #ifdef, #ifndef, #endif…

A preprocessing directive is a line of code that begins with a # sign. The # sign must be the first character on the line excluding any whitespace characters. After the # is the instruction keyword, any number of whitespace characters are allowed between the keyword and the # sign. An entire line of statements constitutes a preprocessing directive that will do certain transformations to the source code before the compiler compiles it.

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326846752&siteId=291194637