Why the statement below is correct even though the type of the string is const char *? As far as I know, the array must be const since I'm trying to type cast from const to non-const object but compilers accept that statement.
char s[] = "test";
This is actually just a special syntax for initializing an array: https://en.cppreference.com/w/c/language/array_initialization
You can initialize a char array using a string literal, which is simply equivalent to declaring an array containing each of the characters in the string (including the null terminator).
"test"is a literal string used as an initializer for thechararray. The literal string is read-only, but the array where it gets copied during initialization does not have to be read-only.