- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Assertions in C/C++
Here we will see what is assertions in C/C++. The C library macro void assert(int expression) allows diagnostic information to be written to the standard error file. In other words, it can be used to add diagnostics in your C program.
Following is the declaration for assert() Macro.
void assert(int expression);
The parameter of this assert() is expression − This can be a variable or any C expression. If expression evaluates to TRUE, assert() does nothing. If expression evaluates to FALSE, assert() displays an error message on stderr (standard error stream to display error messages and diagnostics) and aborts program execution.
Example Code
#include <assert.h> #include <stdio.h> int main () { int a; char str[50]; printf("Enter an integer value: "); scanf("%d", &a); assert(a >= 10); printf("Integer entered is %d\n", a); printf("Enter string: "); scanf("%s", &str); assert(str != NULL); printf("String entered is: %s\n", str); return(0); }
Output
Enter an integer value: 11 Integer entered is 11 Enter string: tutorialspoint String entered is: tutorialspoint
- Related Articles
- Assertions in C#
- Assertions in Java
- Assertions in Python
- Understanding Assertions Cypress
- Lookbehind Assertions JavaScript Regular Expressions
- What are assertions in Selenium with python?
- Assertions in Postman with Chai Assertion Library
- Enable Assertions from the command line in Java
- How to write Assertions in Postman with Chai Assertion Library?
- How to incorporate TestNG assertions in validating Response in Rest Assured?
- What are assertions in Python and how are they carried out?
- What are assertions available to test relational comparisons in Selenium with python?
- How to verify a JSON response body using Assertions in Rest Assured?
- fseek() in C/C++
- strcpy() in C/C++

Advertisements