C language pointer and assert

assert, also known as assertion, needs to include the header file assert.h

It is used to ensure that the program meets the specified conditions at runtime, and if it does not, it will report an error and terminate the operation.

	assert(p != NULL);

The above code verifies whether the variable p is equal to NULL when the program runs to this line of statement. If it is not equal to NULL, the program continues to run, otherwise it will terminate and give an error message prompt.

That is to say, assert can monitor whether the address is empty.

The assert() macro accepts an expression as an argument. If the expression is true (the return value is non-zero), assert() has no effect and the program continues to run. If the expression is false (the return value is zero), assert() will report an error.

 

	assert(p != NULL); 

    if(p ! = NULL)
    {

    }
    else
    {
    }

// 二者功能一致,甚至前者的功能更好

 When assert is not required for program error reporting, we can use #define NDEBUG to close it

Guess you like

Origin blog.csdn.net/2301_76445610/article/details/132211560
Recommended