HomePublic NotesNote detailsFlashcards

Flashcards for:

Comments in C++

When should the 'what' of the code be commented?

Press to flip

The 'what' of the code should be commented when the code is difficult to understand or non-obvious.

What is a comment in C++?

Press to flip

A comment is a text ignored by the compiler and is added to explain the code and why a particular approach is taken.

Why do we add comments in C++?

Press to flip

Comments are added to explain what the code is doing, the reason why a particular approach is chosen, and to make notes for developers reading the code in the future.

What are the types of comments in C++?

Press to flip

There are two types of comments in C++: single line comments and multi-line comments.

How are single line comments added in C++?

Press to flip

Single line comments are added using two backslashes (//).

What are the shortcuts to add single line comments in different operating systems?

Press to flip

In Windows, use Ctrl + backslash; in Mac, use Command + backslash.

How can single line comments be used in debugging?

Press to flip

Single line comments can be used to comment out a single line of code for testing new versions of that line of code.

How are multi-line comments added in C++?

Press to flip

Multi-line comments begin with /* and end with */.

What are the shortcuts to add multi-line comments in different operating systems?

Press to flip

In Windows, use Ctrl + Shift + backslash; in Mac, use Command + Shift + backslash.

Why should unnecessary comments be avoided?

Press to flip

Unnecessary comments should be avoided, especially for obvious code, because they do not add significant value and may clutter the code.

What is considered a best practice for adding comments?

Press to flip

It is considered a best practice to explain the 'why' of a code instead of the 'what', especially if the code is obvious.

When should the 'what' of the code be commented?

Press to flip

The 'what' of the code should be commented when the code is difficult to understand or non-obvious.

What is a comment in C++?

Press to flip

A comment is a text ignored by the compiler and is added to explain the code and why a particular approach is taken.