相关疑难解决方法(0)

C中的NULL总是为零吗?

昨天我正在面试一个中级软件工程职位的人,他提到在C中,NULL并不总是零,并且他已经看到了C的实现,其中NULL不为零.我觉得这很可疑,但我想确定.谁知道他是对的?

(回复不会影响我对这位候选人的判断,我已将决定提交给我的经理.)

c null pointers zero

56
推荐指数
4
解决办法
3万
查看次数

哪一个选择:退出还是退货?

我知道returnexit()(链接)之间的区别,但我不知道在何时何地选择一个而不是另一个.例如,根据这个答案,我理解这return是一个更好的选择,但从另一个我理解相反.

一个例子:在这个代码中(来自这个问题)是否优先使用exit()return

int read_file (char *filename, int **vet)
{
    FILE *fin;

    if ( !(fin = fopen(filename, "r")) )
    {
        perror(filename);
        return -1;
    }

    * vet = malloc (10 * sizeof(int));
    if ( *vet == NULL )
    {
        perror("Memory allocation error.\n");
        return -2;   
    }

    /* ... */

    return fclose(fin);
}

int main ()
{
    char filename[100];
    int *vet;

    if ( read_file(filename, &vet) ) …
Run Code Online (Sandbox Code Playgroud)

c return return-value exit

1
推荐指数
1
解决办法
230
查看次数

标签 统计

c ×2

exit ×1

null ×1

pointers ×1

return ×1

return-value ×1

zero ×1