Question
Book Icon
Chapter 5.5, Problem 23STE
Program Plan Intro

Assert macro:

  • It denotes a tool to ensure that expected conditions are true at assert statement location.
  • If condition does not meet, then program displays error message and aborts.
  • The assert definition is been included in program with statement “#include<cassert>”.
  • The statement “assert(bool_expr)” is inserted to use “assert”, the “bool_expr” denotes a Boolean expression that should be evaluated to true.
  • The assert statement denotes a macro, that is similar to function.
  • The assert macros can be disabled by adding “#define NDEBUG” before include statement.

Given statement:

x=(x*y/z)

Explanation:

  • The given statement denotes an expression with variables “x”, “y” and “z”.
  • It updates the value of “x”.
  • The value of “z” should not be zero.
  • If the value becomes zero, then it displays division by zero error.

Blurred answer
Students have asked these similar questions
The Problem: How do you create a macro that performs two statements.For example we wish to create a cleanup macro:#define CLEAN_RETURN \ close(in_fd);close(out_fd); return;But this code doesn't work if we put it in an if statement:if (done) CLEAN_RETURN;Expanding this we get:if (done) close(in_fd);close(out_fd); return;Let's add a little whitespace for clarity:if (done) close(in_fd);close(out_fd);return;This is not what we intended. One “solution” is to enclose the statementsin {}.#define CLEAN_RETURN \ { close(in_fd);close(out_fd); return; }Now our if statement expands to:if (done) { close(in_fd);close(out_fd); return; };This works. Sort of. The problem is if we try an if / else statement:if (done) CLEAN_RETURN;else not_done_yet();This gives us a syntax error when we try and compile it. Why?Let's look at the expanded code:if (done) { close(in_fd);close(out_fd); return; };else not_done_yet();There's an extra semicolon on the line. This didn't bother us when therewas no else, but now…
Which of these commands stops a macro from expanding?
Briefly explain macro procedure

Chapter 5 Solutions

Problem Solving with C++, Student Value Edition plus MyProgrammingLab with Pearson eText -- Access Card Package (9th Edition)

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage