OpenGenus / cosmos

World's largest Contributor driven code dataset | Used in Quark Search Engine, @OpenGenus IQ, OpenGenus Visual Project
http://internship.opengenus.org
GNU General Public License v3.0
13.53k stars 3.67k forks source link

Update addition_using_bits.c #6712

Closed punam01 closed 8 months ago

punam01 commented 9 months ago

Fixes issue: Added error handling and overflow prevention to the bitwise addition code.

Changes: This pull request introduces several enhancements to the code for adding two numbers using bitwise operators:

  1. Added input validation to ensure that users provide two integer values. If the input is not valid, the program will print an error message and exit with an error code.

  2. Included a check for overflow when performing the bitwise addition. If the addition would result in overflow (exceeding the limits of the int data type), an error message is displayed, and the code returns the maximum possible value for an int (INT_MAX) to indicate an error condition.

  3. Improved code documentation by adding comments to explain the changes made.

The changes make the code more robust and user-friendly, addressing potential issues related to invalid inputs and overflow.