A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

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

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

0

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.

All Answers

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

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?

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

 

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