Curriculum
Course: C basic
Login

Curriculum

C basic

C Introduction

0/1

C Get Started

0/1

C Comments

0/1

C Constants

0/1

C Operators

0/1

C Break and Continue

0/1

C User Input

0/1

C Memory Address

0/1

C Structures

0/1
Text lesson

C Comments

Comments in C

Comments serve multiple purposes in code, enhancing its readability, providing explanations, and facilitating testing by preventing execution of alternative code.

They come in two forms: single-line or multi-line.

Single-line Comments

A single-line comment begins with two forward slashes ( // ).

Anything following these slashes // on the same line is disregarded by the compiler and won’t be executed.

In this example, a single-line comment precedes a line of code.

Example

// This is a comment
printf(“Hello World!”);

In this example, a single-line comment is placed at the conclusion of a line of code.

Example

printf(“Hello World!”); // This is a comment

C Multi-line Comments

Multi-line comments are initiated with  /* and concluded with  */.

Any text enclosed between these symbols will be disregarded by the compiler.

Example

/* The code below will print the words Hello World!
to the screen, and it is amazing */

printf(“Hello World!”);

 

Single or multi-line comments?

The choice between // and /* */ is yours to make. Typically, // is employed for brief comments, while /* */ is preferred for longer ones.

Fun fact: Prior to the release of C99 in 1999, multi-line comments were the only option available in C.