Book
Collection
Click for Table of Contents
© 2025 by Rance D. Necaise
C Primer for Python Programmers
Copyright © 2025
Rance D. Necaise

2.2 Program Comments

Programs written in a high-level language typically contain comments that provide information and act as documentation for the programmer and other readers of the source code.

C provides two styles of comments, single line and multi-line. To specify a single line comment like the comments in Python, you include double slashes (//) at the start of the comment

  1. // This is a single line comment.

Single line comments are generally used for inline comments, those included at the end of a statement on the same line with the statement, and for short comments. For longer comments and description blocks, you can spread a comment over multiple lines as was done in the earlier hello world program. The symbols /* and */ act as delimiters with everything in between treated as a comment.

  1. /* hello.cc
  2.    The hello world program in C.
  3.  */

The use of comments is an important part of writing programs. Someone reading the code, other than the original programmer, may not understand the code or the objective of specific parts of the program. Even the programmer may not remember what the code does months or years later. Some important notes about comments in high-level languages:

  • Comments are not statements and are ignored by the compiler.
  • Comments should be used to describe various statements or groups of statements that may not be obvious at first glance.
  • Comments should not be overused; obvious statements need not be commented.