simple Pointer initialization

前端 未结 7 1773
傲寒
傲寒 2020-12-13 07:14

It has been a while that I used pointers and I just wanna quickly check how I can initialize an integer pointer?

a) int *tmpPtr = 0;

b) int *tmpPtr = null;
         


        
7条回答
  •  悲哀的现实
    2020-12-13 07:59

    I was just refreshing my pointer knowledge and stumbled across this.

    int *tmpPtr = 0;
    

    i find it easier to think of it like this:

    int *tmpPtr ;
    
    tmpPtr = 0 ;
    

    I 'believe' the above 2 lines are equivalent to that one line. so basically the address to be de-referenced is set to 0 or NULL.

提交回复
热议问题