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.
在打印“ Hello world”时 ,如果发生未声明的错误“ Hello” ,则意味着Hello是作为变量而不是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.
仅当在printf()中缺少双引号时这才可能。 要解决此错误,您应该注意双引号。 将常量字符串/文本放在双引号中。
Example:
例:
#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 " characterprintf(Hello world");^
prog.c:4:20: error: missing terminating " characterprintf(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.
要解决此错误,请关闭双引号内的text / string / Hello。
Correct code:
正确的代码:
#include <stdio.h>
int main(void) {
//closing double quote is missing
printf("Hello world");
return 0;
}
Output
输出量
Hello world
翻译自: https://www.includehelp.com/c-programs/hello-or-text-undeclared-while-printing-hello-world-using-printf-error-in-c.aspx