What is ASSERT STATEMENTS?

Showing Answers 1 - 1 of 1 Answers

kashinathn

  • Feb 27th, 2007
 

An ASSERT statement is used to check the value of a single variable at a particular location in the program. It may be placed at any point that a C++ / Java statement could be placed. In the following example, an ASSERT statement is used to insure that the variable x does not have a negative value after the assignment statement.

. . . .
x = y ;
ASSERT( x >= 0, "x has a negative value") ;
cout << "Value of x is " << x << endl ;
. . . .

ASSERT statements are useful to verify that values computed within methods/functions are within acceptable bounds. An ASSERT statement may only be used as a Definition Placed assertion.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions