Comments in CPP
Comments:
- Comments are essential components of C++ code that act as developer annotations.
- They are components of the codebase that are not executable, which means the compiler will not even look at them and they will not affect how the program runs.
- When the original developer revisits the code later, comments help to clarify the reasoning behind the code, making it easier to understand and maintain for everyone.
Single-line comments:
- To produce a single-line comment, use two forward slashes (//).
- Anything on the same line that comes after these slashes is interpreted as a comment and is not performed.
- These help provide the reader with quick remarks or clarifications regarding the next line of code.
- Comments with multiple lines begin with /* and conclude with */.
- They help comment out larger descriptions or information blocks that span several lines.
- This kind of comment is also used to temporarily disable code during development or debugging.
- Comments must be clear, concise, and relevant to the code.
- Do not state the obvious; instead, focus on the "why" instead of the "what."
- As the code changes, keep the comments current.
- Use comments when describing complicated code or choices that are not immediately clear from the code alone.
Labels: CPP


