c - What is the purpose of array[index] = 0;? -
char dev[20] = "dev_name"; char dest[32]; strncpy(dest,dev,sizeof(dev)); dest[sizeof(dev)-1] = 0; what dest[sizeof(dev)-1] = 0; means?
in code, assuming size analogous sizeof,
dev_name[size(dec_name)-1] = 0; dev_name[size(dec_name)-1] points last element of array, remember c arrays use 0 based indexing.
then, definition, string in c exxentially char array with null-termination, if want use char array string, must have null-termination.
0 ascii value of nul or null. so, essentially, you're putting null-terminator char array.
Comments
Post a Comment