Interview Questions

If you can't assign to arrays, then how can

C Interview Questions and Answers


(Continued from previous question...)

If you can't assign to arrays, then how can

Q: If you can't assign to arrays, then how can
int f(char str[])
{
if(str[0] == '\0')
str = "none";
...
}
work?

A: In this code, str is a function parameter, so its declaration is rewritten by the compiler. In other words, str is a pointer (of type char *), and it is legal to assign to it.

(Continued on next question...)

Other Interview Questions