C++ Comments:

Comments allow programmers to make the code more understandable and readable.

With the help of comments, vital information about the corresponding line of code is written, so that even a non-programmer can understand the logic used.

Every programming language supports some form of comments, C++ supports two types of comments, and these are:

  • Single – Line Comments
  • Multi-Line Comments

 

1. Single – Line Comments:

A Single – Line C++ comment starts with //

For example: 

#include <iostream> 

void main() 

{ 

cout << "Hello World"; // prints Hello World 

return 0; 

}

When the above code is compiled, it will ignore

 // prints Hello World 

And final executable code will produce the following result: 

Hello World

However, a Single – Line C++ comment spans only to a single line, so if you write anything like this, then it will not be a comment: 

// C++ Comment Line 1

Line 2

Here, Line 2 is not treated as a comment, but as an executable C++ statement. 

 

2. Multi-Line Comments:

Multi-Line C++ comments start with /* and end with */

For example: 

/* This is a comment */ 


/*Multi – Line C++ comments can also 

Span in multiple lines 

*/

Here, everything written between the starting (/*) and ending (*/) symbols is treated as a C++ comment.

The C++ compiler ignores everything written within the comments, thus it is never executed.

 

C++ Keywords:

Keywords are the words that cannot be used as the names for any constant, variable or an identifier in C++.

It is so because these words already have some predefined meaning to the C++ compiler.

The C++ Keywords are:

asm  else  new  this 
auto  enum  operator  throw 
bool  explicit  private  true 
break  export  protected  try 
case  extern  public  typedef 
catch  false  register  typeid 
char  float  reinterpret_cast  typename 
class  for  return  union 
const  friend  short  unsigned 
const_cast  goto  signed  using 
continue  if  sizeof  virtual 
default  inline  static  void 
delete  int  static_cast  volatile 
do  long  struct  wchar_t 
double  mutable  switch  while 
dynamic_cast  namespace  template 

 

Related Posts:

[yuzo_views]











CopyRight © 2019

CopyRight © 2019