Q:

Error: Unterminated comment (Invalid comment block) in C | Common C program Errors

0

Error: Unterminated comment (Invalid comment block) in C | Common C program Errors

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the program:

#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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now