Error: 'Hello'/Text undeclared while printing Hello world using printf()
While printing "Hello world", if this error 'Hello' undeclared occurred that means Hello is supplied to the compiler as a variable not as a text/string.
This is possible only, when starting double quote is missing inside the printf(). To fix this error, you should take care of double quotes; place the constant string/text in double quotes.
#include <stdio.h>
int main(void) {
//closing double quote is missing
printf(Hello world");
return 0;
}
Output
prog.c: In function ‘main’:
prog.c:4:9: error: ‘Hello’ undeclared (first use in this function)
printf(Hello world");
^~~~~
prog.c:4:9: note: each undeclared identifier is reported only once
for each function it appears in
prog.c:4:15: error: expected ‘)’ before ‘world’
printf(Hello world");
^~~~~
prog.c:4:20: warning: missing terminating " character
printf(Hello world");
^
prog.c:4:20: error: missing terminating " character
printf(Hello world");
^~~
prog.c:6:1: error: expected ‘;’ before ‘}’ token
}
^
What happens, if we use single quote instead of double code in starting of the text/string?
Missing terminating ' character error will be thrown.
How to fix?
To fix this error, close the text/string/Hello within the double quotes.
Correct code:
#include <stdio.h>
int main(void) {
//closing double quote is missing
printf("Hello world");
return 0;
}
Example:
Output
What happens, if we use single quote instead of double code in starting of the text/string?
Missing terminating ' character error will be thrown.
How to fix?
To fix this error, close the text/string/Hello within the double quotes.
Correct code:
Output