Code Comments
Are you ready for the second simplest tutorial in the world? I hope so, because we've already started! You're about to learn everything there is to know about making code comments in C++.Why We Comment
Even if you're an expert programmer, it's not always obvious right away what a block of code does. When programmers are working together on a project, it's important for them to add some remarks in the code to explain what they're doing. But comments are still important if you're just working alone, because you won't always remember writing your own code. A simple comment can help you remember what you were doing.Comments are also useful for temporarily removing part of the code, without deleting it forever. Sometimes you will want to comment a line of code out so you can see how the game runs without it. Other times you may wish to comment out an entire block of code so you can temporarily remove a feature to focus on something else.
Single-line Comments
You can comment out a single line of code by adding two foreward slashes in front of the line. When you do this the text will change colors indicating that it is inactive.
//This is a single-line comment
You can also add a comment to the end of a line of code to explain what it is doing:
model = Model::Box() //create a new box model
Multi-line Comments
You can comment out multiple lines of code by adding "/*" before the block and "*/" after. When you do this the entire section of text will change colors indicating that it is inactive.
/*
This is a multi-line comment
It can span multiple lines
So you don't have to comment out each line one at a time
*/
Conclusion
That's all there is to know about comments in C++. Time to get psyched up, because we're about to get into the nitty-gritty details of C++ programming!