C/C ++ keywords (detailed description)

Source: Internet
Author: User

Cppreference.com->C/C ++ keywords-> Details
C/C ++ keywords ASM

Syntax:

  asm( "instruction" );

ASM allows you to directly insert assembly language commands in your code. Different compilers allow different forms for this command, such:
 

    asm {      instruction-sequence    }

Or

    asm( instruction );    
Auto

The keyword auto is used to declare fully selectable local variables.

Bool

The bool keyword is used to declare Boolean logical variables. That is to say, the variables are either true or false. For example:

    bool done = false;    while( !done ) {    ...    }    

You can also viewData TypesThis page.

Break

The keyword break is used to jump out ofDo,For, OrWhileIt can also endSwitchClause of the statement to allow the program to ignore the following case code. For example:

    while( x < 100 ) {      if( x < 0 )        break;      cout << x << endl;      x++;    }

The break statement can only jump out of the current layer loop. If you want to jump out of a triple nested loop, you need to use other logic or use a GOTO statement to jump out of this nested loop.

Case

InSwitchIt is used to detect matching.

Related Topics:
Default,Switch

Catch

The catch statement usually usesThrowThe statement captures an exception.

Related Topics:
Throw,Try

Char

The keyword char is used to declare a Boolean variable. You can also viewData TypesThis page...

Class

Syntax:

  class class-name : inheritance-list {    private-members-list;        protected:      protected-members-list;    public:      public-members-list;  } object-list;

The keyword class allows you to create a new data type.Class-nameIs the name of the class you want to create, andInheritance-listIs a form of the definition body available for the new class you create. The class is a private member by default, unless the form is marked under the public or protected type.Object-listIs a set of declared objects. For example:

    class Date {      int Day;      int Month;      int Year;    public:      void display();    };

Related Topics:
Struct,Union

Const

The const keyword is used to tell the compiler that a variable that has been initialized cannot be modified.

Related Topics:
Const_cast

Const_cast

Syntax:

  const_cast<type> (object);

The key word const is used to remove "const-ness" data. The target data type must be the same as the original one, except that the target data is not defined by const.

Related Topics:
Dynamic_cast,Reinterpret_cast,Static_cast

Continue

The continue statement is used to end this loop in a loop statement. For example, the following code shows all numbers except 10-20:

    for( int i = 0; i < 21; i++ ) {      if( i == 10 ) {        continue;      }      cout << i << " ";    }

Related Topics:
Break,Do,For,While  

Default

 SwitchStatement.

Related Topics:
Case,Switch

Delete

Syntax:

  delete p;  delete[] pArray;

Delete operation to releasePMemory. the pointer should have beenNewCalled. The second form above is used to delete an array.

Related Topics:
New

Do

Syntax:

  do {    statement-list;  } while( condition );

Do builds a loop statement table until the condition is false. Note that the statements in the loop are executed at least once, because the judgment condition is at the end of the loop.

Related Topics:
For,While

Double

The double keyword is used to declare the precision of floating point variables. You can also viewData TypesThis page.

Dynamic_cast

Syntax:

  dynamic_cast<type> (object);

The keyword dynamic_cast forces a type to be converted to another type and checks its validity during running. If you want to convert two conflicting types, the return value of cast is null.

Related Topics:
Const_cast,Reinterpret_cast,Static_cast

Else

Keyword else used inIfSelect one from the two statements.

Enum

Syntax:

  enum name {name-list} var-list;

The keyword Enum is used to create a name table containing multiple name elements.VaR-listIs optional. For example:

    enum color {red, orange, yellow, green, blue, indigo, violet};    color c1 = indigo;    if( c1 == indigo ) {      cout << "c1 is indigo" << endl;    }
Explicit

When the constructor is specified as an explicit it, the constructor is not automatically used as a conversion constructor. This is only used when an initialization statement parameter matches the form parameter of the constructor.

Extern

The keyword extern is used to inform the compiler that the variables have been declared outside the current range. variables described by the extern statement will not be assigned any space because they have been defined elsewhere.

Extern statements are frequently used for cross-range data transmission between multiple files.

False

"False" is a Boolean value.

Related Topics:
Bool,True

Float

The float keyword is used to declare floating point variables. You can also viewData TypesThis page.

For

Syntax:

  for( initialization; test-condition; increment ) {    statement-list;  }

For constructs a loop composed of four parts:

  1. Initialization can be composed of 0 or more initialization statements separated by commas;
  2. Judgment condition. If this statement is satisfied, it will continue to be executed;
  3. Increment. It can consist of 0 or more incremental statements separated by commas;
  4. Statement body, which consists of 0 or more statements. They are executed when the loop condition is set.

For example:

    for( int i = 0; i < 10; i++ ) {      cout << "i is " << i << endl;    }    int j, k;    for( j = 0, k = 10;         j < k; j++, k-- ) {      cout << "j is " << j << " and k is " << k << endl;    }    for( ; ; ) {      // loop forever!    }

Related Topics:
Do,While

Friend

The keyword "friend" allows a class or function to access private data in a class.

Goto

Syntax:

  goto labelA;  ...  labelA:

The GOTO statement can jump from the current position to the specified flag. Use the GOTO statementHarmful considerationsSo it is not frequently used. For example, Goto can be used to jump out of multiple nestingForLoop, which is more time-effective than the extra logical jump.

Related Topics:
Break

If

Syntax:

  if( conditionA ) {    statement-listA;  }  else if( conditionB ) {    statement-listB;  }  ...  else {    statement-listN;  }

If constructs a branch mechanism that allows different codes to be executed under different conditions.ConditionsIs a judgment statement,Statement-list. If the condition is false, the else statement block will be executed, and all else statements are optional.

Related Topics:
Else,For,While

Inline

Syntax:

  inline int functionA( int i ) {    ...  }

The keyword inline requests the compiler to expand a given function. It sends a call to this function to insert code. The function contains static variables, nested ones, switches, or recursion without inline. When a function declaration is included in a class declaration, the compiler will try to automatically inline the function.
The keyword inline is used to request the compiler to provide a function extended space. It sends a call to this function to insert code. The function containsStaticData, loop,SwitchesOr do not apply inline when recursion. When a function declaration is included in a class declaration, the compiler will try to automatically inline the function.

Int

The Int keyword is used to declare Integer Variables. You can also viewData TypesThis page.

Long

The keyword is used to modify the data type and declare long integer variables. ViewData TypesThis page.

Related Topics:
Short

Mutable

The mutable keyword ignores allConstStatement. A mutable Member of the const object can be modified.

Namespace

Syntax:

  namespace name {    declaration-list;  }

The keyword namespace allows you to create a new space. You can select the name and ignore creating namespace without a name. Once you create a namespace, you must explicitly describe it or use the keywordUsing. Example:

    namespace CartoonNameSpace {      int HomersAge;      void incrementHomersAge() {        HomersAge++;      }    }    int main() {      ...      CartoonNameSpace::HomersAge = 39;      CartoonNameSpace::incrementHomersAge();      cout << CartoonNameSpace::HomersAge << endl;      ...    }

New

Syntax:

  pointer = new type;  pointer = new type( initializer );  pointer = new type[size];

New can allocate a new node to the Data Type and return a first address pointing to the newly allocated memory area. It can also be initialized.SizeAllocable size.

Related Topics:
Delete

Operator

Syntax:

  return-type class-name::operator#(parameter-list) {    ...  }  return-type operator#(parameter-list) {    ...  }

The keyword operator is used to reload functions. Operations that use special characters (#) to describe features in the preceding syntax will be reloaded. If a class is in a class, the class name should be specified. For operations with one dollar,Parameter-listIt should be null. For binary operationsParameter-listIt should contain the operand (the operator on the left is treatedThisPassed ).

For operator members that do not belong to the overload function, the operand on the left is used as the first parameter, and the operand on the right is passed as the second parameter.

You cannot use#,##,.,:,.*, Or?Flag overload.

Private

Data of a private class can only be accessed by its internal members,FriendThe. Keyword private can also be used to inherit a private base class. The base classes of all public and protected members can be converted into private Derived classes.

Related Topics:
Protected,Public

Protected

Data protection is private to their own classes and can be inherited by Derived classes. The keyword can also be used to specify the derivation. The base classes of all public and protected members can be converted into protected Derived classes.

Related Topics:
Private,Public

Public

The public data in the class can be accessed by anyone. The public keyword can also be used to specify the derivation. The basic classes of all the public and protected members can be converted into protected Derived classes.

Related Topics:
Private,Protected

Register

The keyword register requests the compiler to optimize the variables it defines, and this optimization is generally better than manual optimization.

Related Topics:
Auto

Reinterpret_cast

Syntax:

  reinterpret_cast<type> (object);

The reinterpret_cast operation can change one data type to another. It should be used between two irreconcilable pointer types.

Related Topics:
Const_cast,Dynamic_cast,Static_cast

Return

Syntax:

  return;  return( value );

The return statement can jump from the current function to any place where the function is called. The return value is arbitrary. A function can have more than one return statement.

Short

The short keyword is used to modify the data type and declare the short integer variable. ViewData TypesThis page.

Related Topics:
Long

Signed

The signed keyword is used to modify the data type and to declare the variable of the symbol signature type. ViewData TypesThis page.

Related Topics:
Unsigned

Sizeof

The sizeof operation is used to calculate the right expression in bytes and return the number of bytes.

Static

The static data type is used to create a permanent bucket for a variable. static variables remain unchanged during inter-function calls. when static variables are used in a class, this class will mirror the variable.

Static_cast

Syntax:

  static_cast<type> (object);

The keyword static_cast is used for forced conversion between two different types without running time check.

Related Topics:
Const_cast,Dynamic_cast,Reinterpret_cast

Struct

Syntax:

  struct struct-name : inheritance-list {    public-members-list;        protected:      protected-members-list;    private:      private-members-list;  } object-list;

Structs is similarClassesThe members in struct are more like common members in the class. In C, structs can only contain data and cannot contain inherited tables. For example:

    struct Date {      int Day;      int Month;      int Year;    };

Related Topics:
Class,Union

Switch

Syntax:

  switch( expression ) {    case A:      statement list;      break;    case B:      statement list;      break;    ...    case N:      statement list;      break;    default:      statement list;      break;  }

The switch statement allows you to use an expression to determine many numeric values. It is generally used to replace multiple loops.If ()... Else if ()... statement.BreakThe statement must be in eachCaseStatement.DefaultCase is optional. If all cases cannot match, it will match defult case. For example:

    char keystroke = getch();    switch( keystroke ) {      case 'a':      case 'b':      case 'c':      case 'd':        KeyABCDPressed();        break;      case 'e':        KeyEPressed();        break;      default:        UnknownKeyPressed();        break;    }

Related Topics:
Break,Case,Default,If

Template

Syntax:

  template <class data-type> return-type name( parameter-list ) {    statement-list;  }

Templates can be used to create a function template for operations on unknown data types. This template replaces a placeholder with other data types.Data-typeFor example:

    template<class X> void genericSwap( X &a, X &b ) {      X tmp;        tmp = a;      a = b;      b = tmp;    }         int main(void) {      ...      int num1 = 5;      int num2 = 21;      cout << "Before, num1 is " << num1 << " and num2 is " << num2 << endl;      genericSwap( num1, num2 );      cout << "After, num1 is " << num1 << " and num2 is " << num2 << endl;      char c1 = 'a';      char c2 = 'z';      cout << "Before, c1 is " << c1 << " and c2 is " << c2 << endl;      genericSwap( c1, c2 );      cout << "After, c1 is " << c1 << " and c2 is " << c2 << endl;      ...      return( 0 );    }
This

This keyword points to the current object. All belong to oneClassAll function members have a point of this.

Related Topics:
Class

Throw

Syntax:

  try {    statement list;  }  catch( typeA arg ) {    statement list;  }  catch( typeB arg ) {    statement list;  }  ...  catch( typeN arg ) {    statement list;  }

Throw is used in the C ++ system to handle exceptions.TryAndCatchWhen the statement is used together, the C ++ System for exception handling gives the program a more feasible mechanism for error correction.TryWhen executing a piece of code with potential errorsThrowThe statement will be executed, which will jump from the tryCatch. For example:

    try {      cout << "Before throwing exception" << endl;      throw 42;      cout << "Shouldn't ever see this" << endl;    }      catch( int error ) {      cout << "Error: caught exception " << error << endl;    }

Related Topics:
Catch,Try

True

"True" is a Boolean value.

Related Topics:
Bool,False

Try

Try statement to execute code generated by exceptions. ViewThrowStatement to obtain more details.

Related Topics:
Catch,Throw

Typedef

Syntax:

  typedef existing-type new-type;

The typedef keyword allows you to create a new type from an existing type.

Typeid

Syntax:

  typeid( object );

The typeid operation is returned toType_infoThe type of the defined object.

Typename

The keyword typename can be used inTemplateDescribe an undefined type or replace the keyword class.

Union

Syntax:

  union union-name {    public-members-list;        private:      private-members-list;  } object-list;

Unions is similarClasses, Except that all Members share the same memory, its default value is more similar to the public type. For example:

    union Data {      int i;      char c;    };

Related Topics:
Class,Struct

Unsigned

The keyword is used to modify the data type and declare the unsigned integer variable. ViewData TypesThis page.

Related Topics:
Signed

Using

The keyword is used to enterNamespace.

Related Topics:
Namespace

Virtual

Syntax:

  virtual return-type name( parameter-list );  virtual return-type name( parameter-list ) = 0;

The keyword virtual can be used to create a virtual function, which is usually not limited by the derived class. however, if a function is treated as a pure virtual function (expressed by = 0), it must be limited by the derived class.

Volatile

The keyword volatile is used to describe variables, which prevents the compiler from optimizing those variables modified with valatile. Volatile is used in some places where variables can be accidentally changed, for example, throwing an interrupt, without volatile, these variables may conflict with the optimization executed by the compiler.
 

Void

The keyword is used to indicate that a function does not return any value, or normal variables can point to any type of data. void can also be used to declare an empty parameter table. You can also viewData TypesThis page.

Wchar_t

The keyword wchar_t is used to declare the width of the character variable. You can also viewData TypesThis page.

While

Syntax:

  while( condition ) {    statement-list;  }

The keyword while is used for execution as long as the condition is not true.Statement-list. Note that if the starting condition isFalse,Statement-listWill not be executed. (You can useDoLoop To ensure that statement-list is executed at least once.) For example:

    bool done = false;    while( !done ) {      ProcessData();      if( StopLooping() ) {        done = true;      }    }

Related Topics:
Do,For

Related Article

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.