!ok
is the same as ok == 0
.
Remember that in C, any non-zero scalar value in a Boolean context means “true” while zero means “false”. It’s a common C idiom to write !foo
instead of foo == 0
. It works for pointers as well:
FILE *foo = fopen( "some_file", "r" );
if ( !foo )
{
fprintf( stderr, "could not open some_file\n" );
return EXIT_FAILURE;
}
So, while ( x )
is the same as while ( x != 0 )
, and while ( !x )
is the same as while ( x == 0 )
.
solved What does a ! operator mean if put in front of a variable?