C Guide – Comments
November 23, 2009 Leave a comment
Comments are very important in programming. Could you imagine what you would do if you wrote a program that was hundreds of lines long, and you forgot what a certain function did? or what that variable was for?!
What is a Comment?
SO, what is a comment I hear you cry? A comment is a line (or lines) of code – text to be honest – that will not be read by the compiler when you run the code. So you could comment out a whole function, and the compiler would act as if that function didn’t even exist at all! (poor function 😦 )
Comments – The Ways
In C there are two ways – to my knowledge… – of creating comments in a C program. The first way is this:
So here, if you place ‘//’ at the beginning of a line in C, then the rest of the line we become a comment!
The second way to create a comment is like shown below:
Here, if you place ‘/*’ at the beginning of a line, and ‘*/’ at the end of the line you want to be a comment, then that whole line will turn into a comment.
Even better, if you do what the image shows above, you can place ‘/*’ on one line and ‘*/’ on another line, and you can comment out 2+ lines at once! This is miles better than comments out 100 lines by typing 100 ‘//’ 😀
All you need is an ‘/*’ on line 1, and an ‘*/’ on line 100, and wallah!
Next is Variables, these are vital if you really want to do some neat stuff with your code 😀