Monday, December 1, 2008

Comments in different Programming Languages

Comments are helpful medium for storing useful information in application codes while developing it. A successful software is not only represented by how well it does it task but also by how well it is documented and how well it's programming logic can be understood by a new comer. So, the software enhancements can be supported by new comer, which helps in long run of the software.

 

Without writing any further on its usefulness, I will directly move to the topic. There are two types of comments in programming languages. One is single line comment, which works for the line where it is given. It usually has starting mark but no ending mark. Other is multi-line comment, which works for until the closing mark is found.

 

Comment in C, C++, C#, PHP

A single line comment is preceded by double slash (//).  An example is shown below.

 

//function to reverse an array

Int reverse(int a[])

{

            //code goes her

}

No doubt, you can use double slash to comment multiple consecutive lines provided that each line is preceded by double slash (//).

Multi-line comment starts with single slash and an asterisk sign (/*) and ends with (*/).

 

Int reverse(int a[])

/*function to

            reverse an array */

 

This commenting style is applicable for many programming languages.

 

Comment in VB, ASP, VBScript

Single line comment is preceded by single apostrophe (').

 

Comment in SQL Server

Single line comment is preceded by double dash (--) while multi-line comment is represented by text between (/*) and (*/) marks.

If you give comment inside comment, then also whole thing is represented as comment.

 

Comment in HTML

Multi-line comment begins with (<!--) and ends with (--!>). An example is shown below.

<!--<div id="footer">                   

                    ©2008 Aptech Suraj Lubhu

                </div>-->

 

Comment in JavaScript

Comment in JavaScript is similar as in C and C++. Single line comment is preceded by double slash (//) while multi-line comment begins with (/*) and ends with (*/) marks.

 

Comment in CSS Style Sheets

Multi-line comments in CSS are preceded by (/*) and followed by (*/).

 

0 comments: