Home »
C programs »
C common errors programs
Error: Unterminated comment (Invalid comment block) in C | Common C program Errors
Here, we will learn how and when "Unterminated comment" error occurs (Invalid comment block) in C and how to fix it?
By IncludeHelp Last updated : March 10, 2024
Comments are used to write logic explain or anything that you do not want to compile. In C language there are two types of comments 1) Single line comment and 2) Multi-line comment.
Read: Comments in C language
Error: Unterminated comment (Invalid comment block)
Unterminated comment error occurred when we do not terminate the comment with a valid set of characters.
Single line comment does not need to terminate, and it starts by a double slash (//), but, multiple line comment needs to be terminated by */ (asterisk and slash).
Consider the program:
Example
#include <stdio.h>
int main(void) {
/*printf is used to print a message \*
printf("Hello world");
return 0;
}
Output
prog.c: In function ‘main’:
prog.c:5:5: error: unterminated comment
/*printf is used to print a message \*
^
prog.c:3:1: error: expected declaration or statement at end of input
int main(void) {
^~~
How to fix Unterminated comment error in C
Note that, multiple line comment are placed between /* and */, terminate the comment properly with valid characters.
Correct Code
#include <stdio.h>
int main(void) {
/*printf is used to print a message*/
printf("Hello world");
return 0;
}
Output
Hello world
C Common Errors Programs »