Using the C/C++ comments program example


Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: Using the C/C++ comments in C++ programming

To show: How to use the comments in C++ and C programming




// comments in C/C++, using /* */ or //

#include <iostream>


int main(void)


/* this is a comment

and it extends until the closing

star-slash comment mark */


std::cout<<"Hello World! How are you?\n";


// this comment ends at the end of the line so, new comment line need new double forward slash


std::cout<<"That is the comment in C/C++ program!\n";

std::cout<<"They are ignored by compiler!\n";


// double forward slash comments can be alone on a line

/* so can slash-star comments */



return 0;



Output example:


Hello World! How are you?

That is the comment in C/C++ program!

They are ignored by compiler!

Press any key to continue . . .



C and C++ Programming Resources | C & C++ Code Example Index