*haystack++ != *needle++

如下的代码判断 needle_start指向的串是否为haystack_start指向的串的前缀,如不是,则返回NULL。
比如:"abcd1234" 就包含了 "abc" 为前缀

char* prefix(char* haystack_start, char* needle_start)
{
    char* haystack = haystack_start;
    char* needle = needle_start;
 
    while(*haystack && *needle){
        if(______________________________) return NULL;  //填空位置
    }
    
    if(*needle) return NULL;
    
    return haystack_start;

}

答案: *haystack++ != *needle++ 

解析:

1、++运算符高于*运算符  ,所以先做++运算,此时++操作符产生一份haystack的拷贝,记为A
2、++操作符增加haystack的值
3、在A上进行*操作符,间接访问。对于needle是同样的道理

类似于
int i, j;
j=i++; 
先取了i的值赋给j,然后++。这里是先用*取了needle指向的值,然后++

你可能感兴趣的:(*haystack++ != *needle++)