Online Test Banks
Score higher
See Online Test Banks
eLearning
Learning anything is easy
Browse Online Courses
Mobile Apps
Learning on the go
Explore Mobile Apps
Dummies Store
Shop for books and more
Start Shopping

How to Insert Comments in C Source Code

Like other programming languages, C lets you insert comments in your code. The comments are skipped over by the compiler but remain in the source code as a way for you to jot down notes, your intentions, general information, or rude remarks about your customers.

In the C language, comments are enclosed between two sets of characters, /* and */,

/* like this. */

Everything between those two pairs of characters is ignored by the compiler.

Note that both character sets are required. Unlike other programming languages, C doesn't limit comments to a single line or from a certain position to the end of a line. Comments in C are more like a marked block in a word processor; the comment has a beginning and an end. This can cause some confusion, especially if you're not using a color-coded editor. (In a color-coded editor, commented text shows up as one color, making it easy to see where a /* or */ is misplaced.)

The most basic form of comment is a source code heading, which identifies you as the programmer as well as any other information you think you should save.

/* DUMMIES.C source code. By Ima C. Programmer. 28Feb2010 */

This heading is used to identify the program, the programmer, and the date. Often, other information is put in there as well, depending on the circumstances under which the program was written. It's just basic information that might be useful later.

Comments can span multiple lines, too, like this:

/* NOTE: added a beep to the following line
   The \a is the Alert or bell character */

By having the /* start at one line and the */ end at another, the single comment is able to span two lines.

Comments don't add anything to the size of the program, nor do they slow down the code. They're just notes or suggestions for you or any other programmer who may work on the code again later.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win $500. Easy.