Description

Code comments are non-executable instructions that programmers can use to provide documentation. Single-line comments describe a single line in code.

Program comments can be placed anywhere.

  1. A single line Comment can be placed anywhere in the program.
  2. Comments lines start with '//'
  3. Compilers ignore symbols written after '//'.

Multi-line Comment

  1. Anywhere can be used for a multi-line comment.
  2. Multi-line comments starts with '/*' and ends with '*/'.
  3. Any symbols written between '/*' and '*/' are ignored by Compiler.
  4. Multiple lines can be user.

Method 1: 

// Online C compiler to run C program online
#include <stdio.h>
int main() {
    
    char comment[50];
    int i = 2, a = 0;
    
    printf("Enter Comment : ");
    gets(comment);
    if(comment[0] == '/'){
        if(comment[1] == '/'){
            printf("This is Single Line Comment.");
        }
        else if(comment[1] == '*'){
            for(i = 2; i <= 50; i++){
                if(comment[i]=='*' && comment[i + 1] == '/'){
                    printf("This is Multi Line Comment.");
                    a = 1;
                    break;
                }
                else{
                    continue;
                }
            }
            if(a == 0){
                printf("It is not a comment");
            }
        }
        else{
            printf("It is not a comment");
        }
    }
    else{
        printf("It is not a comment");
    }
    
    return 0;
}

Method 2:

#include<stdio.h>
#include<string.h>

void main(){
    char com[30];
    int len;
    printf("\nEnter Comment : ");
    gets(com);
    len = strlen(com);
    if(com[0] == '/' && com[1] == '/'){
        printf("It is a Single Line Comment");
    }
    else if(com[0] == '/' && com[1] == '*' && com[len - 1] == '/' && com[len - 2] == '*' ){
        printf("It is a Multi Line Comment");
    }
    else{
        printf("It is not a comment");
    }
}

Please Comment...

Comments

Login is mandatory to comment Please login

Recommended Posts

Linear search in c | Algorithm of Linear search | c programming

It is the easiest search algorithm because it starts at the beginning and works through each element in a list until the desired element is located.

calculate the GCD | Euclids Algorithm | c and cpp programming language

The G.C.D. ( Greatest Common Divisor ) or H.C.F. ( Highest Common Factor ) of two numbers is the largest positive integer that perfectly divides the two given numbers.

Implement queue using linked list C program

In computing, queues are linear data structures that follow the First In, First Out (FIFO) principle. They are used to perform enqueuing and dequeuing operations.

Fascinating number or not in c and cpp

Check given number is fascinating number or not in c programming language.