C++ Keywords


A keyword is a reserved word. We can not use them as a variable name, constant name etc.
 private  true  break
 else  new  auto
 this  enum  double
 bool  explicit  register
 false  catch  public
 extern  case  try
 export  union  return
 class  typename  reinterpret_cast
 float  char  typeid
 protected  typedef  if
 unsigned  short  friend
 for  const  int
 static  inline  continue
 default  goto  signed
 using  struct  wchar_t
 volatile  sizeof  static_cast
 delete  long  do
 asm  template  namespace
 dynamic_cast  mutable  switch
 while

private

private - members cannot be accessed (or viewed) from outside the class. If someone tries to access the private members of a class, they will get a compile-time error. By default class variables and member functions are private.

 class PrivateAccess
  {
    private:
    int x;
    void display();
  }

true

true is a keyword, it has the value 1.

 bool x ;
&nbap;x = true ;

break

break is a loop control statement that is used to terminate the loop.

 for ( int c = 1 ; c < 5 ; c++ )
 {
   if ( c > 2 )
        break;
    cout << c << endl;
    c++;
  }

if and else keyword

Use if to specify a block of code to be executed, if a specified condition is true.
Use else to specify a block of code to be executed if the same condition is false.

  if( conditionA )
  {
    // if condition is true this code is executed
  }
 else
  {
    // if condition is not true this code is executed
  }

double

The double is a fundamental data type in C++. It is used to define numeric variables holding numbers with decimal points.

 double area ;
 area = 323323.14 ;

new

new keyword is used for memory allocation on the Heap.

 MyClass obj = new MyClass() ;
&nbap;area = 323323.14 ;

auto

The auto keyword is used to declare a variable that has a complicated type.

this

this is a keyword that is used to refers to the current instance of the class.

enum

enum is a user defined data type which is used to assign constant names to a group of numeric integer values.

bool

bool is a data type that is used to declare a variable whose value will be set as true or false ( true mean 1 or false mean 0).

try and catch keyword

The try keyword is used to define a block of code to be tested for errors while it is being executed.
The catch keyword is used to define a block of code to be executed, if an error occurs in the try block.

false

false is a keyword, it has the value 0.

public

public means everyone is allowed to access. public - members can be accessed (or viewed) from outside the class. The data members and member functions declared public can be accessed by other classes too.

case

case is a keyword that is used to test a variable against a certain value in a switch statement

union

union is a keyword. It is a user-defined datatype. A union is like a class, except that all members of a union share the same memory location.

return

return is a keyword. This keyword causes execution to jump from the current function to whatever function called the current function. An optional value can be returned. A function may have more than one return statement.

class

class is a keyword. It is a user-defined data type.class - keyword holds its own data members and member functions, which can be accessed and used by creating an instance of that class.

Post a Comment

0 Comments