Integer type (typically 4 bytes, -2,147,483,648 to 2,147,483,647)
1st Parameter
An integer expression that is evaluated; if the expression is false (zero), the program terminates with an error message.
Read more about parameters of assert in parameters section
The assertfunction in C language Tests the given condition and causes a program abort if false.
The assert macro is used to verify assumptions made by the program and print a diagnostic message if this assumption is false. If the assertion fails, the program will terminate by calling abort(). Assertions are often used to check for programming errors and should not be used to handle expected runtime errors. In release builds, assertions can be disabled by defining the NDEBUG macro.
The assertfunction takes 1
parameter:
•
int `expression`: An integer expression that is evaluated; if the expression is false (zero), the program terminates with an error message.
Evaluates a specified expression, and if the result is false (zero), it writes an error message to `stderr` and terminates the program. Used for debugging and ensuring assumptions are valid at runtime.
The assert function return value :
This macro does not return a value
If the assertion fails, the program terminates
Output
This example demonstrates the basic usage of the `assert` macro to check for a division by zero error. The program will run normally for the first division, but will terminate when attempting to divide by zero.