【问题标题】:warning - assignment makes integer from pointer without a cast. WHY?警告 - 赋值从没有强制转换的指针生成整数。为什么?
【发布时间】:2012-03-07 12:04:21
【问题描述】:

为什么会在标题中给出警告?

    char name[10];
    for (i=0; i<10; i++){
        name[i] = NULL;

【问题讨论】:

    标签: pointers warnings case variable-assignment


    【解决方案1】:

    你想要name[i]=0;name[i]='\0';。在 C 中,NULL 是(或者,更准确地说,可能是)一个指针。

    例如,ANSI C 允许以下内容:

    #define NULL ((void *)0)
    

    有关更多信息,请参阅 C 常见问题解答中 Question 5.9 的末尾。请注意,NULL 在 C++ 中略有不同。

    【讨论】:

      【解决方案2】:

      我们不使用 null 作为字符,在您的情况下 Name[i] 是字符, 你最好使用空字符'\0'

      【讨论】:

        猜你喜欢
        • 2011-07-04
        • 2015-10-19
        • 2013-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多