Error: 'Hello'/Text undeclared while printing Hello world using printf()

Here, we will learn why an Error: 'Hello'/Text undeclared while printing Hello world using printf() and how to fix it in C programming language?
By IncludeHelp Last updated : March 10, 2024

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.

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 " 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 - Error: 'Hello'/Text undeclared while printing Hello world using printf()

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;
}

Output

Hello world

C Common Errors Programs »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.