Categories:
.NET (357)
C (330)
C++ (184)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (2)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How can I ensure that integer arithmetic doesnt overflow?
How can I ensure that integer arithmetic doesnt overflow?
✍: Guest
The usual approach is to test the operands against the limits in the header file <limits.h> before doing the operation. For example, here is a ``careful'' addition function:
int
chkadd(int a, int b)
{
if(INT_MAX - b < a) {
fputs("int overflow\n", stderr);
return INT_MAX;
}
return a + b;
}
2015-03-04, 1692👍, 0💬
Popular Posts:
If we inherit a class do the private variables also get inherited ? Yes, the variables are inherited...
How do you locate the first X in a string txt? A) txt.find('X'); B) txt.locate('X'); C) txt.indexOf(...
The object that contains all the properties and methods for every ASP.NET page, that is built is .. ...
What is XSLT? XSLT is a rule based language used to transform XML documents in to other file formats...
What will be printed as the result of the operation below: main() { int x=10, y=15; x = x++; y = ++y...