Sunday, 21 June 2015

Assert Function in C

How To Use Assert Function in C Programs


How To Use : The  Assert Function in c Programs Using Header Present in the Standard Library Of C Language. That is Defines The Macro assert.

 Syntax:  <assert.h>

The Macro Implements an Assertion. That Can Be Used To Verify The Assumptions Made in the Program. The Macro Assert Diagnostic insertions in the program. When executed if the expression is false ( equal to 0 ), Assert Writes information about the call that failed in stderr and then calls abort.

More About Specifically, assert function in c Program Below.

Program
alltechprograms


#include <stdio.h>
#include <assert.h>

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;

}


Output 

Input two integers to divide
24
12

24/12=12.0

No comments:

Post a Comment