The empty character constant '' can not be cout or assigned to character in C++. The compiler will say "error: expected expression". Can we put it in C++ source code? If not, what's the usage of ''? (empty character constant '' is one ' followed with another ')
-
6Why do you think, that "empty character constant" is a thing? Why do you need it? – Algirdas Preidžius Dec 20 '18 at 13:42
-
5What value is `''` supposed to have? – Blaze Dec 20 '18 at 13:42
-
FWIW, a null string `""` is a thing, as there is actually a null terminator there. `''` has no such behavior. – NathanOliver Dec 20 '18 at 13:46
-
2@Tobi "_I don't understand why people downvote this._" Hover over the downvote button: "_This question does not show any research effort_". – Algirdas Preidžius Dec 20 '18 at 13:48
-
@AlgirdasPreidžius Can it be understood that empty character constant '' is just a pure grammar error just like a variable being named as 2018ch ? Have thought that empty character constant '' could be some use just like empty string "", considering that compiler even give it a name "empty character constant". – lst Dec 20 '18 at 13:49
-
@lst It’s not *the* ‘Empty Character Constant’. It’s *a* character constant, that is empty. – Biffen Dec 20 '18 at 13:51
-
Possible duplicate of https://stackoverflow.com/questions/18410234/how-does-one-represent-the-empty-char – Biffen Dec 20 '18 at 13:52
-
1@lst 1) If compiler issues an error, when compiling it, one, by the definition, cannot use it, in any way, unless the whole goal is to issue a compilation error. 2) Empty string literal is a thing, since it is not, empty. It contains just a single string terminator: `'\0'` character. What would the value of empty `char` literal be? 3) Consider learning from a [good C++ book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – Algirdas Preidžius Dec 20 '18 at 13:53
-
An empty character constant is more like an empty integer constant than an empty string. Your compiler can tell you about an empty character constant because of a character's absence between `'` marks, while the absence of an integer is indistinguishable from nothing. – molbdnilo Dec 20 '18 at 14:21
3 Answers
Can we put it in C++ source code?
No, it would be a syntax error.
If not, what's the usage of ''?
There is no usage, unless your purpose is to cause a compilation error (for which there are probably better alternatives such as static_assert
).
Can it be understood that empty character constant '' is just a pure grammar error just like a variable being named as 2018ch ?
Yes. The grammar says:
character-literal: encoding-prefix opt ' c-char-sequence '
Notice that unlike the encoding-prefix
, c-char-sequence
is not optional.
Side note: Yes, it is a character sequence - multi character literals exist. But you don't need to learn about them yet other than knowing that you probably won't need them. Just don't assume that they're strings.

- 232,697
- 12
- 197
- 326
''
makes no sense and thus it won't compile, what value is it supposed to have?
Remember, it's all just bits and bytes in memory at some point so what value should the bytes have that represent ''
?
char a = 0;
//or
char a = '\0';
These represent "empty" chars which is the closest you'll get to ''
.

- 35,759
- 6
- 62
- 122
-
Started well but that's no more an "empty" char than `''` is – Lightness Races in Orbit Dec 20 '18 at 14:03
-
-
Have a +0.666667 vote :) Shame about the truncation to int ;) – Lightness Races in Orbit Dec 20 '18 at 15:03
Ok I think that the confusion comes from the fact that a string can be an empty string e.g. ""
, so maybe you draw a parallel and expect there to be an empty character something like ''
.
Well remember what a string is: a series of characters (0, 1, or more) (terminated by the end of string character '\0'
). So ""
is a string of 0 characters (end of string character not counted, although it is there), aka the "empty string".
A character is well... just that one character. Not zero, not 2 or 3. A character always has a value. Thus the empty character ''
does not exist and makes no sense.

- 72,283
- 15
- 145
- 224