Home > Articles > Programming > C/C++

  • Print
  • + Share This
This chapter is from the book

Q&A

Q

What does #include do?

A

This is a directive to the preprocessor that runs when you call your compiler. This specific directive causes the file in the <> named after the word #include to be read in as if it were typed in at that location in your source code.

Q

What is the difference between // comments and /* style comments?

A

The double-slash comments (//) expire at the end of the line. Slash-star (/*) comments are in effect until a closing comment mark (*/). The double-slash comments are also referred to as single-line comments, and the slash-star comments are often referred to as multiline comments. Remember, not even the end of the function terminates a slash-star comment; you must put in the closing comment mark or you will receive a compile-time error.

Q

What differentiates a good comment from a bad comment?

A

A good comment tells the reader why this particular code is doing whatever it is doing or explains what a section of code is about to do. A bad comment restates what a particular line of code is doing. Lines of code should be written so that they speak for themselves. A well-written line of code should tell you what it is doing without needing a comment.

  • + Share This
  • 🔖 Save To Your Account