c - What is the underlying mechanism of char array[] = "string"? -


i know in c string assignment must go through

char string[4]; strcpy(string, "aaa"); 

but why , how c allow

char string[] = "string"; 

?

thanks in advance

char string[] = "string"; 

here, right length of string automatically calculated compiler there's enough room string , nul character.

char string[4]; strcpy(string, "aaa"); 

here strcpy may access beyond array bounds if string larger actual string capacity.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -