Thursday, 30 May 2013

The assert Macro in C

The assert macro is useful in checking conditions at run time and is very useful while debugging a program. To use assert macro the header file <assert.h> is included. The prototype of assert is as follows. 

void assert(int expression);

Where expression is any valid c language expression. If the condition holds true then the program execution will continue otherwise the execution is terminated and an error message is displayed. The error message displays file name, line number, function name, and the condition which failed.


int main()
   int a, b;
   printf("Input two integers to divide\n");
   scanf("%d%d", &a, &b);
   assert(b != 0);
   printf("%d/%d = %.2f\n", a, b, a/(float)b);
   return 0;

Click here to download the C Program. 

No comments:

Post a Comment