Comments

Location
  1. Courses

    /

  2. Quick C course

    /

  3. Comments

We can add comments to the code. The purpose of that is to explain the parts of the code that may be hard to understand or to warn the reader (Example: Hey, do not do 'that' or the program will crash).

A comment written on one line starts with two slashes:

// Single-line comment.

And a multi-line comment is surrounded by '/*' and '*/':

1
2
3
4
5
/* A multi-line comment. */

Here is a commented code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* The main function of the program. The execution of the program happens inside its braces. After its last instruction is executed, the program stops. */ int main() { // Defines a variable of type 'int' called 'var': int var; /* Returns the error code 0 to the operating system, indicating that the program ended successfully. */ return 0; }