Tuesday, July 28, 2009

How to add comments in C programming?

plz suggest me how to add comment in C programming?


is it /* xyz */ ? or // xyz ?

How to add comments in C programming?
/* */ - is the only one used in c..


c++ has both
Reply:Both are correct.


It is valid both in c as well as c++.


// is used for single line comment


/*


Used


for multiline


comment


*/





One important thing to note is that, comment should note be within another comment.


/*


first line


/*


second line


*/


third line


*/


These kind of comments are invalid.


Hope u got cleared now
Reply:MULTILINE COMMENTS:/*HI*/





INVALID COMMENT:/*.............*/..................
Reply:// this is the valid style of commenting in c





/* */ this is used in c++..





i hope it helped u
Reply:You're right. Both /* */ and // work in c++. But some compilers of C do not support //.


Try Turbo C. Do a google search for "Turbo C download" and click on the first result.


It supports //
Reply:hi there.


/* You need 2 comment in C like dis */
Reply:both work..


// comments one line only


/*..*/ can comment more than one line.. (a whole block)
Reply:If you want to give a single line comment, try this:





int a=5; //initialization





or a multiline comment you can give this:





/*


Addition Of Two Numbers


By Bill Gates


© Microsoft Corporation


*/





Mostly multiline comments (/* */) are used for documentation. ir providing info about the program





Regards


Praveen Kumar
Reply:I can't believe how many people answered with misleading or incomplete answers. People, don't post guesses.





C definitely supports /* Comment here */ type comments. Such comments are multiline comments, so you can have


/*


Comment 1


Comment 2


*/





The question is with inline comments that are a part of C++.


code here // comment here


Note that they are not multiline. Inline comments are OK in C99, but in C90 they are not.





So you need to find out how old your C compiler is and what standard it supports. If it supports C99, you know it supports inline comments, otherwise no.
Reply:as per listed answer





Thanks





Rikin B Pandya
Reply:C compilers only accept text within /* */ as comments.


C++ compilers accept text within both /* */ and // as comments.





Remember: You can't have nested comments, e.g.


/* hello


/* I am here */





*/





A good way to provide comments is:





/*


* %26lt; text here%26gt;


* %26lt;text here%26gt;


*


*/

mint

No comments:

Post a Comment