What is '\ 0' in C ++?

I am trying to translate a huge project from C ++ to Delphi, and I am completing the translation. One of the things I left is the monster '\ 0'.

if (*asmcmd=='\0' || *asmcmd==';') 

where asmcmd char *.

I know that \ 0 marks the end of an array type in C ++, but I need to know it as a byte. Is it 0?

In other words, will the code below be the equivalent of a C ++ string?

 if(asmcmd^=0) or (asmcmd^=';') then ... 

where asmcmd is PAnsiChar.

You don't need to know Delphi to answer my question, but tell me \ 0 as a byte. This will work too. :)

+6
c ++ operators delphi translation
source share
3 answers

'\0' is 0 . This is a relic from C that doesn't have a string type at all and uses char arrays instead. A null character is used to indicate the end of a line; not a very wise decision in retrospect - most other string implementations use a special counter variable somewhere, which does the search for the end of the line O (1) instead of CO (n).

*asmcmd=='\0' is just a minimized way to check length(asmcmd) == 0 or asmcmd.is_empty() in a hypothetical language.

+13
source share

Strictly this is an escape sequence for a character with an octal value of zero (which, of course, is also zero in any database).

Although you can use any number with a zero prefix to indicate an octal character code (for example, '\040' is an ASCII character space), you rarely have to. '\ 0' is idiomatic for specifying a NUL character (because you cannot enter such a character from the keyboard or display it in your editor).

You can also specify "\ x0", which is the NUL character expressed in hexadecimal format.

The NUL character is used in C and C ++ to end a string stored in an array of characters. This view is used for string string constants and conditionally for strings that are managed by the <cstring> / <string.h> library. In C ++, you can use the std :: string class instead.

Note that in C ++, a character constant such as '\0' or 'a' is of type char . In C, perhaps for unclear reasons, it is of type int .

+5
source share

This is a char value for null or a char value of 0 . It is used at the end of the line.

+3
source share

All Articles