Share:
Notifications
Clear all

Single-line comment in C Programming Language

1 Posts
1 Users
0 Reactions
92 Views
(@kajal)
Posts: 313
Reputable Member
Topic starter
 

A single-line comment is used to write short notes or explanations in your C code.
It helps make the code more readable and document what each part does, but the compiler ignores it during compilation.

Syntax

// This is a single-line comment
  • Starts with two forward slashes (//)

  • Everything written after // on the same line is treated as a comment

  • The compiler does not execute that part

 

Example 1: Simple Comment

#include <stdio.h>

int main() {
    // This program prints Hello, World!
    printf("Hello, World!");
    return 0;
}

The comment // This program prints Hello, World! is ignored by the compiler.

Output:

Hello, World!

Example 2: Inline Comment

You can also place a single-line comment after a statement on the same line.

int x = 10;  // Assign 10 to variable x
 
Posted : 08/11/2025 12:25 pm
Share: