First of all, this line
if(!(temp = (double*)realloc(data, capacity*sizeof(double))))
should look like
if(!(temp = realloc(data, capacity*sizeof(double))))
because as per this discussion we need not to cast the return value of malloc()
and family in C
..
That said, to break down the statement,
-
First,
temp = realloc(data, capacity*sizeof(double))
gets evaluated. This statement reallocatesdata
to have a memory allocated equal to the size ofcapacity*sizeof(double)
bytes. The returned pointer is stored totemp
. -
Then essentially the whole statement reduces to
if (! (temp))
. This check for the success of therealloc()
call by checking the returned pointer against NULL.-
If
realloc()
failed, it returned NULL, and theif
will evaluate to TRUE, so the program will executeexit(1);
and get over. -
If
realloc()
is a success,temp
will have a non-NULL pointer, thereby, theif
check will fail and the program will continue normally.
-