Check for integer overflow on multiplication | CPP program to check for integer overflow on multiplication ; Function to check whether there is overflow in a * b or not . It returns true if there is overflow . ; Check if either of them is zero ; Driver code
#include <iostream> NEW_LINE using namespace std ; bool isOverflow ( long long a , long long b ) { if ( a == 0 b == 0 ) return false ; long long result = a * b ; if ( a == result / b ) return false ; else return true ; } int main ( ) { long long a = 10000000000 , b = -10000000000 ; if ( isOverflow ( a , b ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }