a ++ or a-- is postfix. It will process the data before increasing/decreasing the amount. For example : b = a++; 'b' in the above case would be 'a', while 'a' will change to (a+1) ++a and --a is prefix. Meaning that they will decrease/increase the value first before processing data/commands. For example : b = ++a; 'b' in the above case would be (a+1), and 'a' would also be (a+1)
Discussions

what is "{0}" in C? - Stack Overflow
In the particular case of string, usually, the character whose ASCII value is 0 terminates the string. For example, if you wanted to put a string that reads 'Hello world' inside the string you could have done More on stackoverflow.com
🌐 stackoverflow.com
Is there a way to take in ‘\0’ as an input from the user?
yeah, but how you do it probably depends on your terminal. I have to press Ctrl-@ to get a \0 into stdin. You can also put one into a file or have a different command generate it, and redirect it into your program. More on reddit.com
🌐 r/C_Programming
15
15
December 10, 2023
c++ - What does the symbol \0 mean in a string-literal? - Stack Overflow
What does the \0 symbol mean in a C string? It's the "end" of a string. A null character. In memory, it's actually a Zero. Usually functions that handle char arrays look for this character, as this is the end of the message. I'll put an example at the end. More on stackoverflow.com
🌐 stackoverflow.com
while loop - using 0 instead of '\0' in C program - Stack Overflow
For example, the line feed character with decimal value 10 can be typed inside a string out as \012 (octal) or \xA (hex). These are called octal/hexadecimal escape sequences. Example: ... Similarly, we can write the null character using escape sequences, either octal \0 or hex \x0. More on stackoverflow.com
🌐 stackoverflow.com
🌐
PW Skills
pwskills.com › blog › cpp › 0-in-c-how-does-the-0-and-0-work-in-c
0 in C++: How does the -'0' and +'0' work in C?
If an array is initialized with fewer values than its size, the remaining elements are automatically initialized to zero. Example: int array[5] = {0}; // Initializes all elements of the array to 0
🌐
GeeksforGeeks
geeksforgeeks.org › c language › difference-between-null-pointer-null-character-0-and-0-in-c-with-examples
Difference between NULL pointer, Null character ('\0') and '0' in C with Examples - GeeksforGeeks
July 15, 2025 - if(!pointer) Null Characters('\0'): '\0' is defined to be a null character. It is a character with all bits set to zero. This has nothing to do with pointers. '\0' is (like all character literals) an integer constant with the value zero.
🌐
Narkive
programming.comp.narkive.com › HE49XQWj › in-c-programming-what-is-meant-by-0-or-null
In C programming, what is meant by \0 or null?
\0 is just a zero byte. That is, a byte that actually contains the number zero. It is used in C to mark the end of a string. For example, if you want to store "Hello" in a typical C-style string, you would use 6 bytes, holding 'H', 'e', 'l', 'l', 'o', '\0'. The zero byte marks the end of the ...
🌐
C For Dummies
c-for-dummies.com › blog
The Difference Between NULL and Zero | C For Dummies Blog
Keep in mind that no one is offended when you use a zero value to terminate a string; the \0 escape sequence simply allows you to specify it within a set of quotes. That may be required, for example, when a function demands a char value as input and not an int.
Find elsewhere
🌐
Programiz
programiz.com › c-programming › c-operators
Operators in C
April 27, 2022 - A relational operator checks the relationship between two operands. If the relation is true, it returns 1; if the relation is false, it returns value 0. Relational operators are used in decision making and loops.
🌐
Reddit
reddit.com › r/c_programming › is there a way to take in ‘\0’ as an input from the user?
Is there a way to take in ‘\0’ as an input from the user? : r/C_Programming
December 10, 2023 - So one method of accepting a null from users, is allowing them to escape it - exactly as you're doing in your code (where the compiler has to .. accept a null as input from a user). ... This! Escape characters exist for this purpose… use \0 and write code to parse accordingly.
🌐
Quora
quora.com › What-is-use-of-0-in-the-C-programming-language
What is use of \0 in the C programming language? - Quora
Answer (1 of 8): In C, \0, aka NUL character is conventionally used as string terminator, so one doesn’t need to explicitly store string length but can compute it by figuring out the position of NUL character. For more information see Null character.
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 92124 › difference-between-0-and-0-and-0
c++ - Difference between "\0" and '\0' and 0 | DaniWeb
October 8, 2007 - For example: char word[10] = "Oxford"; char number[10] = "01234"; Depending on typeface used 'O' may look exactly like '0' making it … — Lerner 582 Jump to Post · '\0' is the null character used to terminate strings in C/C++.
Top answer
1 of 7
107

sizeof str is 7 - five bytes for the "Hello" text, plus the explicit NUL terminator, plus the implicit NUL terminator.

strlen(str) is 5 - the five "Hello" bytes only.

The key here is that the implicit nul terminator is always added - even if the string literal just happens to end with \0. Of course, strlen just stops at the first \0 - it can't tell the difference.

There is one exception to the implicit NUL terminator rule - if you explicitly specify the array size, the string will be truncated to fit:

char str[6] = "Hello\0"; // strlen(str) = 5, sizeof(str) = 6 (with one NUL)
char str[7] = "Hello\0"; // strlen(str) = 5, sizeof(str) = 7 (with two NULs)
char str[8] = "Hello\0"; // strlen(str) = 5, sizeof(str) = 8 (with three NULs per C99 6.7.8.21)

This is, however, rarely useful, and prone to miscalculating the string length and ending up with an unterminated string. It is also forbidden in C++.

2 of 7
12

The length of the array is 7, the NUL character \0 still counts as a character and the string is still terminated with an implicit \0

See this link to see a working example

Note that had you declared str as char str[6]= "Hello\0"; the length would be 6 because the implicit NUL is only added if it can fit (which it can't in this example.)

§ 6.7.8/p14
An array of character type may be initialized by a character string literal, optionally enclosed in braces. Sucessive characters of the character string literal (including the terminating null character if there is room or if the array is of unknown size) initialize the elements of the array.

Examples

char str[] = "Hello\0"; /* sizeof == 7, Explicit + Implicit NUL */
char str[5]= "Hello\0"; /* sizeof == 5, str is "Hello" with no NUL (no longer a C-string, just an array of char). This may trigger compiler warning */
char str[6]= "Hello\0"; /* sizeof == 6, Explicit NUL only */
char str[7]= "Hello\0"; /* sizeof == 7, Explicit + Implicit NUL */
char str[8]= "Hello\0"; /* sizeof == 8, Explicit + two Implicit NUL */
🌐
Idallen
teaching.idallen.com › c_programming › differentWaysToWriteZero.html
Different Ways to Write Zero in C - Teaching
January 19, 2003 - Updated: 2003-01-19 05:50 · Please be clear on the different ways of saying "zero" in C:
🌐
Medium
medium.com › @veranjali2503 › understanding-return-0-in-c-programming-10e8512edb1d
Understanding return 0; in C Programming | by Anjali Verma | Medium
March 24, 2025 - A return value of 0 typically means ... to represent different types of errors. Example: return 1; for a file not found error, return 2; for memory allocation failure, etc....
Top answer
1 of 11
446

Note: This answer applies to the C language, not C++.


Null Pointers

The integer constant literal 0 has different meanings depending upon the context in which it's used. In all cases, it is still an integer constant with the value 0, it is just described in different ways.

If a pointer is being compared to the constant literal 0, then this is a check to see if the pointer is a null pointer. This 0 is then referred to as a null pointer constant. The C standard defines that 0 cast to the type void * is both a null pointer and a null pointer constant.

Additionally, to help readability, the macro NULL is provided in the header file stddef.h. Depending upon your compiler it might be possible to #undef NULL and redefine it to something wacky.

Therefore, here are some valid ways to check for a null pointer:

if (pointer == NULL)

NULL is defined to compare equal to a null pointer. It is implementation defined what the actual definition of NULL is, as long as it is a valid null pointer constant.

if (pointer == 0)

0 is another representation of the null pointer constant.

if (!pointer)

This if statement implicitly checks "is not 0", so we reverse that to mean "is 0".

The following are INVALID ways to check for a null pointer:

int mynull = 0;
<some code>
if (pointer == mynull)

To the compiler this is not a check for a null pointer, but an equality check on two variables. This might work if mynull never changes in the code and the compiler optimizations constant fold the 0 into the if statement, but this is not guaranteed and the compiler has to produce at least one diagnostic message (warning or error) according to the C Standard.

Note that the value of a null pointer in the C language does not matter on the underlying architecture. If the underlying architecture has a null pointer value defined as address 0xDEADBEEF, then it is up to the compiler to sort this mess out.

As such, even on this funny architecture, the following ways are still valid ways to check for a null pointer:

if (!pointer)
if (pointer == NULL)
if (pointer == 0)

The following are INVALID ways to check for a null pointer:

#define MYNULL (void *) 0xDEADBEEF
if (pointer == MYNULL)
if (pointer == 0xDEADBEEF)

as these are seen by a compiler as normal comparisons.

Null Characters

'\0' is defined to be a null character - that is a character with all bits set to zero. '\0' is (like all character literals) an integer constant, in this case with the value zero. So '\0' is completely equivalent to an unadorned 0 integer constant - the only difference is in the intent that it conveys to a human reader ("I'm using this as a null character.").

'\0' has nothing to do with pointers. However, you may see something similar to this code:

if (!*char_pointer)

checks if the char pointer is pointing at a null character.

if (*char_pointer)

checks if the char pointer is pointing at a non-null character.

Don't get these confused with null pointers. Just because the bit representation is the same, and this allows for some convenient cross over cases, they are not really the same thing.

References

See Question 5.3 of the comp.lang.c FAQ for more. See this pdf for the C standard. Check out sections 6.3.2.3 Pointers, paragraph 3.

2 of 11
45

It appears that a number of people misunderstand what the differences between NULL, '\0' and 0 are. So, to explain, and in attempt to avoid repeating things said earlier:

A constant expression of type int with the value 0, or an expression of this type, cast to type void * is a null pointer constant, which if converted to a pointer becomes a null pointer. It is guaranteed by the standard to compare unequal to any pointer to any object or function.

NULL is a macro, defined in as a null pointer constant.

\0 is a construction used to represent the null character, used to terminate a string.

A null character is a byte which has all its bits set to 0.

🌐
Programiz
programiz.com › c-programming › c-strings
Strings in C (With Examples)
August 28, 2021 - In this tutorial, you'll learn about strings in C programming. You'll learn to declare them, initialize them and use them for various I/O operations with the help of examples. In C programming, a string is a sequence of characters terminated with a null character \0.
🌐
Yeldar
yeldar.org › blog › zero-in-c
Zero in C – Yeldar Kudaibergen
C lacks a built-in boolean data type, as found in more modern programming languages. Instead, integer values are used, where 0 represents "false" and 1 (or any non-zero value) represents "true".