---
title: 1.20 Comments and Whitespace
description: "Comments are non-executable text used to document source code. Whitespace separates tokens and improves readability without generally affecting how C interprets the program. ``` #include int main() { // Display a message printf(\"Hello\\n\"); /* Display another message on the next…"
url: "https://edcret.in/docs/c-programming/basic-refreshers/1-20-comments-and-whitespace/"
updated: "2026-09-06"
category: C Programming / Basic Refreshers
---

# 1.20 Comments and Whitespace

Comments are non-executable text used to document source code. Whitespace separates tokens and improves readability without generally affecting how C interprets the program.

```
#include <stdio.h>

int main()
{
    // Display a message
    printf("Hello\n");

    /*
       Display another message
       on the next line.
    */
    printf("C programming\n");

    return 0;
}
```

### Example Output

```
Hello
C programming
```

### Explanation

C provides two forms of comments.

A single-line comment begins with `//` and continues to the end of the line:

```
// Display a message
```

A block comment begins with `/*` and ends with `*/`:

```
/*
   Display another message
   on the next line.
*/
```

Comments are ignored during translation and do not produce executable operations themselves.

### Whitespace

Whitespace includes spaces, tabs, and newlines. It is generally used to separate tokens and format source code.

These statements are equivalent:

```
int number = 10;
```

```
int
number
=
10
;
```

Whitespace can also be omitted where tokens remain unambiguous:

```
int number=10;
```

However, whitespace can be required to separate adjacent tokens. For example:

```
int number;
```

cannot be written as:

```
intnumber;
```

because `intnumber` is interpreted as a single identifier.

### Comment and Whitespace Reference

| Element | Syntax | Purpose |
| --- | --- | --- |
| Single-line comment | `// ...` | Comment through the end of the line |
| Block comment | `/* ... */` | Comment spanning one or more lines |
| Space | `` | Separates and formats tokens |
| Tab | `\t` | Whitespace used for formatting |
| Newline | Line break | Separates source lines and improves formatting |

Comments and whitespace can improve source-code readability, but comments do not affect the runtime behavior of the program.
