C-lines have zero completion, which means that in char -array char in the index strlen()there is a byte with all bits set to 0. I saw code where '\0'an integer is used instead 0. But since sizeof(int) > sizeof(char), it can actually write for the allocated space for the array - am I mistaken? Or does the compiler explicitly discard a intin charin such a situation?
strlen()
'\0'
0
sizeof(int) > sizeof(char)
int
char
Yes, you are mistaken - the zero value will be truncated. After all, if you write:
char c = 0;
, c, . - :
char c = 12345;
. GCC :
c.c:2: warning: overflow in implicit constant conversion
.
0 char s, int char.
'\0' int ( , ), somechararray[x]=0 somechararray[x]='\0' .
somechararray[x]=0
somechararray[x]='\0'
'\0', , .
Source: https://habr.com/ru/post/1732658/More articles:Would you use VersionOne also as a bug tracking system (like BugZilla) - issue-trackingВ чем разница между всплывающим окном, хромированным окном, модальным окном, лайтбокс, объявлением наведения? - javascriptGoogle Test and Visual Studio 2010 RC - c ++Java and thermal printer - javaPerformance bottleneck - Linq to SQL or database - how do I say? - performanceOutOfMemory error while trying to retrieve a large jar using ZipFileSet - javasecret key for iphone access device - securityUnexpected output Prolog script - prologHow to make links load or update in a web browser in android? - androidHelp with basic keys and unique constraints - sqlAll Articles