- The C Standard Library
- C Library - Home
- C Library - <assert.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <float.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdarg.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <time.h>
- C Standard Library Resources
- C Library - Quick Guide
- C Library - Useful Resources
- C Library - Discussion
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
C library macro - assert()
Description
The C library macro void assert(int expression) allows diagnostic information to be written to the standard error file. In other words, it can be used to add diagnostics in your C program.
Declaration
Following is the declaration for assert() Macro.
void assert(int expression);
Parameters
expression − This can be a variable or any C expression. If expression evaluates to TRUE, assert() does nothing. If expression evaluates to FALSE, assert() displays an error message on stderr (standard error stream to display error messages and diagnostics) and aborts program execution.
Return Value
This macro does not return any value.
Example
The following example shows the usage of assert() macro −
#include <assert.h> #include <stdio.h> int main () { int a; char str[50]; printf("Enter an integer value: "); scanf("%d", &a); assert(a >= 10); printf("Integer entered is %d\n", a); printf("Enter string: "); scanf("%s", str); assert(str != NULL); printf("String entered is: %s\n", str); return(0); }
Let us compile and run the above program in the interactive mode as shown below −
Enter an integer value: 11 Integer entered is 11 Enter string: tutorialspoint String entered is: tutorialspoint
assert_h.htm
Advertisements
To Continue Learning Please Login
Login with Google