Is NULL the same as zero?
#1

Let's say I have declared an array and initialized first two slots of it with zeros:
Код:
#define NULL '\0'
new array[5] = { 0, 0, NULL, NULL, NULL };
I loop through it now:
Код:
for(new i=0; array[i]!=NULL; i++)
  printf("%i", array[i]);
Is it going to print two zero elements or maybe it assumes zeros are the same as NULL elements? Thanks
btw, can't check it myself now, sorry
Reply
#2

In Scripting/Coding term, NULL is equals to 0
Reply
#3

In this case NULL is 0, as \0 is the ascii escape character for 0. But in general it isnt. Null often is an own "third" state that means some value is not defined.
E.g. in OO programming it is commonly used as default value for uninitialized objects. So an object is NULL until you actually create it. This again references to 0 as "false" memory reference, but it means slightly more than just this.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)