这是什么原因?我认为如果一个指针为null,那么其余的条件将不会被评估。为什么有条件导致seg故障?
// doesn't work:
char *ptr = somefunction();
if (ptr && ptr[0] == '1' || ptr[0] == 't')
// ...
// does work:
char *ptr = somefunction();
if (ptr)
if (ptr[0] == '1' || ptr[0] == 't')
// ...
这里不是你的问题,但请注意,仅仅因为指针是非空的并不意味着它是有效的...... –