C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs

Home » C programs » assert.h header file functions

assert() function of assert.h in C

In this article, we are going to learn about the use assert() function of assert.h header file in C language, and use it to hold the process till 0 passes as a parameter.
Submitted by Manu Jemini, on April 04, 2018

If you are looking for a function which keeps track of a variable’s value. If the value changes, the function tells about it, otherwise not.

Using assert function comes up mainly during testing, when you want to check for all the variables during the program lifecycle. This can also be useful in debugging, if your program got lots of manipulation and you want to check if value of a variable crosses certain limit or even changes.

To make use of assert just call it with the variable of your choice.


    Assert (a)
    This will keep track of value of a.

assert.h - assert() function Example in C

#include <stdio.h>
#include <assert.h>
int main()
	// Defining variables
	int a;
	// Assigning value of a=2
	a = 2;
	// Displaying the value of a
	printf("Value of a is: %d\n", a);
	// assert function will not exit till the value of a =0
	// now change the value of a=0
	a = 0;
	// Displaying the value of a
	printf("Value of a is: %d\n\n", a);
	// again calling the function with different parameter
	return 0;


assert.h - assert()  in c language

You may also be interested in...

C/C++ Tips and Tricks...

Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.

Comments and Discussions