Concept: assertion / assert() in C / C++ programing language.
Question: Interview, Programming, C / C++ concept
Explain use of “assert” in C / C++ in details with example. etc.
assert is a pre-processor macro ideally used for debugging purpose
It basically checks the condition passed to it and if it is true program continues execution if the condition is false the program aborts at that point and prints debugging information. what information is printed depends on compiler. Mostly the condition at which it failed and also line number and file name etc.
Advantage of assert is that if you define a macro #define NDEBUG before the line that includes the assert.h header file, the assert calls will be ignored by compiler which means during development you can make sure that conditions are checked how ever after the release of the product (with above macro) all the over head is gone in the final compilation