nerver suppose that a point value is NULL or int value is 0 when defined a variant

来源:互联网 发布:人人分销系统源码 编辑:程序博客网 时间:2024/06/16 03:13


when I read some book about C/C++, it's always give a hint that an int variant is assigned to zero automatically . however it doesn't always the tureth

see the test code:

/* by vinco at 2011-08-03* os : Ubuntu* compiler :CC for GCC*/#include<stdio.h>int main(){        char* str;// = NULL;        int i;//=0        if(NULL == str)                printf("str == NULL\n");        else                 printf("str != NULL\n");        if( 0==i )                printf("i == 0\n");        else                printf("i != 0\n");        return 0;}

when compile and run it:


root@vinco:/home/vinco# make  nullcc     null.c   -o nullroot@vinco:/home/vinco# ./nullstr != NULLi != 0


you'd better initial the variant firstly once you define it, to make your code more robust or less bug!