Do "!" and "zero" give the same result?

In objective-c, the end result is the !variablesame. variable==nilAlso, I think I read somewhere that iVars are initialized to "nil" (ie o), but unfortunately I cannot find where I noticed this now . If I am right, is this initialization for the zero part of the iVar declaration or is it related to something like @property?

i.e. they value the same ...

if(!myObject) ...

and

if(myObject == nil) ...

Greetings to Gary.

Edited: hopefully for clarity.

+3
source share
3 answers

Your question, question and question seem to be asking different things, so ...

: , ! nil . ! - , (.. !0 1 ! - 0), nil - 0.

: , !foo foo == nil . , 0. .

+3

! C- , (, & || ).

nil - .

TRUE, NULL nil.

, if(!myObject) if(myObject==nil) .

+1

In objective-c, it !is a Boolean operator and returns the opposite value of a boolean or expression. In the example below, myObj really evaluates this pointer value as Boolean, zero, or nonzero. Since myObj is a non-zero pointer, this evaluates to true.! myObj will return the opposite, in which case it will return false.

id myObj = nil;
int x = 0;
if (myObj)
  x++;
+1
source

Source: https://habr.com/ru/post/1776304/


All Articles