cpp comments

c++ comments

c++ introduces a new comment symbols//(double slash) The comments start with a double forward slash symbol and terminate at the end of the line.

A comment may start anywhere in the line of the program, and whatever follows till the end of the line is ignored.

Note that there is no closing symbol of the double slash comment(//) or single line comments the double slash(//) comment is basically as single line comment.

and The Multiline comments can be written as follows

// this is an example of single line comment
// this is c++ single line comment
// c++ is a power full language

Now lets take example of comments to understand

// variable A to represent Average salary (Single line comment)
/* variable A to represent Average salary and this is program for find average salary */ (multi line comment)

Given below are 3 important points regarding comments:

1. The space should not be between the // (forward slashes) Take the examples

/    / is incorrect. because there is space between forward slashes
as same, there should not be any space between the slash and star characters in
/* and */ correct
/* and *    / incorrect.

2. Comments do not nest, Example /* programming */ comment has no special meaning inside /* */ Similarly, // comment has no special meaning inside

3. should not write comments inside character literals (such as characters enclosed between single quotes). Comments inside String literals (such as, the text enclosed between double-quotes) are behave as part of the String’s content.

The another multiline comments are also symbols /* this is multiline comment*/

are still valid and are some suitable for multiline comments the following comment is allowed

/* an example of c++ multiline comments*/

The comments may be single line or multiple line. we can write comments anywhere in the program for example double slash comments cannot be used int the manner as shown below

for(i=0; i < n; / * loops n times * / i++) examples of single line comment

The example of single line comment

#include<iostream>
int main()
{
// printing string
cout<<"This is c++ program";
return 0;
}

The example of Multi line comment

#include<iostream>
int main()
{
/* printing string this is multi line comment */
cout<<"This is c++ program";
return 0;
}

  • C++ Dynamic Initialization of Objects
  • C++ Copy Constructor
  • C++ Dynamic Constructor
  • C++ Destructors
  • C++ Exercise
  • C++ Operator Overloading
  • C++ Overloading Unary Operators
  • Const pointer in C
  • Void pointer in c
  • C++ Overloading Binary Operators
  • C++ Overloading Binary Operators Using Friends
  • C++ Manipulation String Using Operators
  • C++ Rules for overloading operators
  • C++ Exercise
  • C++ Basic To class Type
  • C++ Class TO Basic Type
  • C++ One class To another class type
  • C++ Exercise
  • C++ Inheritance introduction
  • C++ Single Inheritance
  • C++ Multiple Inheritance
  • C++ Ambiguity Resolution in inheritance
  • C++ Hierarchical Inheritance
  • C++ Hybrid Inheritance
  • C++ Virtual Base Classes
  • C++ Exercise
  • C++ abstract class
  • C++ nesting of classes
  • C++ Exercise
  • C++ polymorphism
  • C++ Exercise
  • C++ pointers
  • C++ Pointers TO object
  • C++ this pointer
  • C++ Pointer to Derived class
  • C++ Virtual functions
  • C++ Exercise
  • C++ streams
  • C++ unformatted I/O operations
  • C++ Put() and get()
  • C++ getline() and write()
  • C++ Formatted console I/O
  • C++ Manipulators
  • C++ Exercise
  • C++ file handling
  • C++ file stream classes
  • C++ Open and closing file
  • C++ open using constructor
  • C++ open using open()
  • C++ Detecting End of file
  • C++ File modes
  • C++ File pointers and Manipulators
  • C++ Sequential I/O
  • C++ Reading and Writing
  • C++ Updating a File
  • C++ Error handling In File
  • C++ Command Line Arguments
  • C++ Exercise
  • C++ Template introduction
  • C++ Class Templates with multiple Parameters
  • C++ Function templates
  • C++ Function templates with multiple parameters
  • C++ member function Template
  • C++ Exercise
  • C++ Exception handling
  • C++ Basics of Exception Handling
  • C++ Exception Handling Mechanism
  • C++ Throwing Mechanism
  • C++ Catch Mechanism
  • C++ Catch all Exceptions
  • C++ Re-Throwing An Exception
  • C++ Specifying Exceptions
  • C++ Exercise