Code comments are non-executable instruction that programmers can use provide documentation. Single-line comments describe a single line in code.
Program comments can be placed anywhere.
// Method 1: To detect the comment
#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: To check the comment
#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");
}
}
Comments
Oops!