How to save '\ 0' in char array

Is it possible to save a char '\0'inside a char array and then store different characters after? for instance

char* tmp = "My\0name\0is\0\0";

I was taught that it is actually called a string list in C, but when I tried to print above (using printf("%s\n", tmp)), it printed only

"My".

+4
source share
2 answers

Yes, of course, it is possible, however, in addition, you cannot use this array as a string and get the contents stored after '\0'.

char, , '\0'. (, , '\0' , %s printf()).

C11, §7.1.1,

, . [...]

, , .

+5

, tmp. , printf, , , , \0

, tmp

int main(int c,char** a){
    char* tmp = "My\0name\0is\0\0";
    write(1,tmp,12);
}
+1

Source: https://habr.com/ru/post/1666161/


All Articles