Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Suppose you have a class <code>MyClass</code> then by convention <code>nil</code> is used if you want to initialize its instance to null value (same as <code>null</code> in java) i.e.<br></p> <pre><code>MyClass *obj = nil; </code></pre> <p><br> and if you want to initialize a primitive pointer to null value (same as in c) you use <br></p> <pre><code>int *ptr = NULL; </code></pre> <p><br>and if you want to initialize to <code>Class</code> reference to null value (same as <code>null</code> in java) then use<br></p> <pre><code>Class classRefOfMyClass = Nil; </code></pre> <p>It's just a convention otherwise Nil or nil have same meaning and perhaps NULL , nil or Nil all are same.</p> <p>Here is the definition for these in <code>objc.h</code> file</p> <pre><code>#ifndef Nil # if __has_feature(cxx_nullptr) # define Nil nullptr # else # define Nil __DARWIN_NULL # endif #endif #ifndef nil # if __has_feature(cxx_nullptr) # define nil nullptr # else # define nil __DARWIN_NULL # endif #endif </code></pre> <p>And in <code>stddef.h</code></p> <pre><code>#define NULL ((void*)0) </code></pre> <p>And the definition of <code>__DARWIN_NULL</code> in <code>_types.h</code></p> <pre><code>#define __DARWIN_NULL ((void *)0) </code></pre> <p>So there is no difference logically. The main idea here is to initialize a pointer whether <code>C</code> or <code>Objective-C</code> to <code>0</code>. If you have knowledge of <code>C</code> then you can assign </p> <pre><code>int *ptr = 0; </code></pre> <p>without type casting <code>0</code> to a pointer. As you don't need to typecast <code>0</code> to assign it to a pointer.</p> <h1>In short they all are <code>0</code> and nothing else.</h1>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload