Your line char *str = '\0'; actually DOES set str to (the equivalent of) NULL. This is because '\0' in C is an integer with value 0, which is a valid null pointer constant. It's extremely obfuscated though :-)

Making str (a pointer to) an empty string is done with str = ""; (or with str = "\0";, which will make str point to an array of two zero bytes).

Note: do not confuse your declaration with the statement in line 3 here

char *str;
/* ... allocate storage for str here ... */
*str = '\0'; /* Same as *str = 0; */

which does something entirely different: it sets the first character of the string that str points to to a zero byte, effectively making str point to the empty string.

Terminology nitpick: strings can't be set to NULL; a C string is an array of characters that has a NUL character somewhere. Without a NUL character, it's just an array of characters and must not be passed to functions expecting (pointers to) strings. Pointers, however, are the only objects in C that can be NULL. And don't confuse the NULL macro with the NUL character :-)

Answer from Jens on Stack Overflow
🌐
C For Dummies
c-for-dummies.com › blog
Null Versus Empty Strings | C For Dummies Blog
A null string has no values. It’s an empty char array, one that hasn’t been assigned any elements. The string exists in memory, so it’s not a NULL pointer.
🌐
Northern Illinois University
faculty.cs.niu.edu › ~winans › CS501 › Notes › cstrings.html
C Strings
A valid C string requires the presence of a terminating "null character" (a character with ASCII value 0, usually represented by the character literal '\0'). Since char is a built-in data type, no header file needs to be included to create a C string. The C library header file <cstring> contains ...
🌐
Quora
quora.com › What-is-a-null-string-in-C
What is a null string in C? - Quora
Answer (1 of 2): The term “null string” is very ambiguous in a language like C. It might mean that you have a pointer to char which is set to NULL. In this case, there is no string at all.
🌐
Wikipedia
en.wikipedia.org › wiki › Null-terminated_string
Null-terminated string - Wikipedia
March 25, 2025 - In computer programming, a null-terminated string is a character string stored as an array containing the characters and terminated with a null character (a character with an internal value of zero, called "NUL" in this article, not same as the glyph zero). Alternative names are C string, which ...
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 58206-setting-string-null.html
Setting a string to null
... By setting a "string to NULL", ... want to make it an empty string? >strcpy(string, NULL); This isn't a good idea, strcpy expects both arguments to be non-null pointers to C-style strings....
Find elsewhere
🌐
Sololearn
sololearn.com › en › Discuss › 1751325 › multiple-null-characters-in-string-literal
Multiple Null Characters in String Literal | Sololearn: Learn to code for FREE!
C strings are null-terminated and C++ strings aren't. In your fist example, you are implicitly casting a `char*`-type string literal to a `std::string`, and, because in a C string, '\0' is considered end-of-string, it won't read any further.
🌐
Reddit
reddit.com › r/c_programming › how do i print out the null value in a string?
r/C_Programming on Reddit: How do I print out the null value in a string?
December 4, 2023 -

I learned in C that a string ends with a null value, "\0". How do I print out this null value in C?

I tried doing this by scanning the string "paint". However, it doesn't seem to work -

```
#include <stdio.h>
int main() {
char name[100];
scanf("%s", name);
printf("The name is %c", name[5]);
}

```

This is my output -
```
paint

The name is some weird symbol looking like 0

Process finished with exit code 0

```

🌐
GeeksforGeeks
geeksforgeeks.org › c language › strings-in-c
Strings in C - GeeksforGeeks
November 14, 2025 - ... String literals are automatically null-terminated. They are typically stored in read-only memory, so modifying them causes undefined behavior. You can assign string literals to char*, but it's recommended to use const char* for safety.
🌐
Reddit
reddit.com › r/cpp_questions › std::string::data() is const but c++ strings are not null terminated. does data() return a copy or a reference to the underlying string?
r/cpp_questions on Reddit: std::string::data() is const but C++ strings are not null terminated. Does data() return a copy or a reference to the underlying string?
November 22, 2020 -

If data() returns a reference, it needs to append the underlying array with a null terminator, in which case it may need to perform a reallocation which modifies the pointer in the string and data()’s implementation cannot be const.

If data() returns a copy, then this is a major difference between string and vector<char> and I’ve learned something.

I’m not at my laptop so can’t write a simple program where I modify the array returned from data() then print the string.

🌐
Cplusplus
cplusplus.com › forum › general › 44832
String NULL? - C++ Forum
With char's is actually no different. You can return NULL, but if the calling function tried to print it, then you're going to get problems. So the calling function has to handle the case of getting a NULL back. IMHO, throwing an exception is somewhat more universal since the calling function ...
🌐
Reddit
reddit.com › r/learnprogramming › c#, how can someone create a null string?
r/learnprogramming on Reddit: C#, how can someone create a null string?
May 20, 2023 -

Don't all strings get initialized as an empty string? And if they get initialized as null...why... What kind of design decision is that.

The editor forces me to use string? temp = Console.ReadLine()

because if I use string it's possible it can be null. How?? Even if they just press enter it still would just be an empty string. An empty string isn't null, it's just empty. I don't see how someone could pass the program null as a value.

EDIT: Case closed

🌐
Microsoft Learn
learn.microsoft.com › en-us › sql › odbc › reference › develop-app › character-data-and-c-strings
Character Data and C Strings - ODBC API Reference | Microsoft Learn
Although applications and drivers commonly use C strings (null-terminated arrays of characters) to hold character data, there is no requirement to do this. In C, character data can also be treated as an array of characters (without null-termination) ...
🌐
PrepBytes
prepbytes.com › home › c programming › null character in c
Null Character in C
August 3, 2023 - When processing C strings, functions ... accordingly. Q2: Can the Null character be part of a string in C? Ans: Yes, the Null character can be part of a string in C, but it will act as the string terminator....
🌐
Blogger
chrisoldwood.blogspot.com › 2011 › 11 › null-string-reference-vs-empty-string.html
The OldWood Thing: Null String Reference vs Empty String Value
This leads to the common technique of using a special value to represent NULL instead:- ... Because of the way strings in C are represented (a pointer to an array of characters) you can use a NULL pointer here instead, which chalks one up for the null reference choice:-