3 ms·
Semantically, arrays are different from pointers. They do, however, degrade into pointers in many situations, which causes that misunderstanding.
by kqr 9y ago
Semantically, arrays are different from pointers. They do, however, degrade into pointers in many situations, which causes that misunderstanding.
- petecox 9y agoA language with an array type, e.g. Java, distinguishes between a 'null' array reference and an array of zero length. which could substitute in languages that don't have an option type; SOME([]) vs NONE But a plain *char in C makes no such distinction.
- charliesome 9y agoThere is a difference. An empty string in C is a non-null char* pointer pointing to a zero byte. Passing a null pointer to strlen will crash.
- esrauch 9y agoA zero-length array can't ever be a valid cstring at all since they have to be null terminated. I don't think that is actually relevant to the claim you are replying to, which is about arrays and pointers and not strings.