[C编码笔记] 空串与NULL是不一样的

int main()
{
    char *str = NULL;
    printf("%p \n", str);
    printf("%p \n", &str);
    return 0;
}

str地址有值,但是str的值为0,是无效的内存地址

int main()
{
    char *str = "";
    printf("%p \n", str);
    printf("%p \n", &str);
    return 0;
}

str指向一个存储空串的地址,是有效地址

猜你喜欢

转载自www.cnblogs.com/xinglichao/p/9495527.html