Comments in C are non-executable lines used to explain code. They are written for humans, not for the compiler, making programs easier to understand, debug, and maintain.

In simple words:

Important Note

There are two types of comments in C:

 1. Single-line Comments (//)

✅ Syntax:

// This is a comment

Example 1: Comment Before Code

#include <stdio.h>

int main() {
    // This line prints Hello World on screen
    printf("Hello World!");
    return 0;
}

Output:

Hello World!

Example 2: Comment at End of Line

#include <stdio.h>

int main() {
    printf("Hello World!"); // Printing message
    return 0;
}

Useful when you want to explain a specific line.

Example 3: Disable Code Using Comments

#include <stdio.h>

int main() {
    printf("This will run\n");

    // printf("This will NOT run\n");

    return 0;
}

Here, the second printf is disabled using comments.

2. Multi-line Comments (/* */)

✅ Syntax:

/* This is a multi-line comment */

Example 1: Block Description

#include <stdio.h>

int main() {

    /* 
       This program prints Hello World
       It is a basic C program example
    */
    
    printf("Hello World!");

    return 0;
}

Example 2: Comment Multiple Lines of Code

#include <stdio.h>

int main() {

    /*
    printf("Line 1\n");
    printf("Line 2\n");
    */

    printf("Only this line will execute\n");

    return 0;
}

 Both printf statements inside the comment are ignored.

Feature

Single-line (//)

Multi-line (/* */)

Usage

Short notes

Long explanations

Lines Supported

One line

Multiple lines

Readability

Quick comments

Detailed description

Common Use

Inline comments

Block comments

int a = 10; // Assign 10 to a (not useful)
int a = 10; // Initial value for score

Historical Note