Crystal Indigo!
Crystal Indigo!
Providing all solutions you need anytime
+27 76 626 8187
NOTE: Questions maybe different
Question 1 The assert statement
1. tests conditions or assumptions that should not occur in a program to prevent runtime errors
2. will display an error message when the condition in the statement is not true and abort the
program.
3. All of the other options are valid.
4. can be turned on and off in a program
Question 2 Base your answer to this question on the highlighted
directives at the beginning of the program.
The program below will abort and display that the assertion has failed
#define NDEBUG
#include <cassert >
int main()
{
int x = 7;
/* Some big code in between and let's say x
is accidentally changed to 9 */
x = 9;
// Programmer assumes x to be 7 in rest of the code
assert(x==7);
/* Rest of the code */
return 0;
}
1. True
2. False