Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 979231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:11:12+00:00 2026-05-16T04:11:12+00:00

Possible Duplicate: Best way to detect integer overflow in C/C++ i have tried to

  • 0

Possible Duplicate:
Best way to detect integer overflow in C/C++

i have tried to implement simple program which tests if overflow occurs during integer addition:

#include <climits>
#include <iostream>
#include <string>

using namespace std;

string overflow(long a,long b){
    return ((a+b)>UINT_MAX)?"true":"false";
}

int main(){
    long a, b;
    cout << "enter a and b: ";
    cin >> a >> b;
    string m = overflow(a,b);
    cout << m;

    return 0;
}

UINT_MAX=65535 so i have entered 65535 and 20 but it wrote false why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:11:13+00:00Added an answer on May 16, 2026 at 4:11 am

    Given unsigned int a, b, this expression can never evaluate to true:

    (a+b) > UINT_MAX
    

    The reason why it can’t ever be true is because UINT_MAX is the max, so whatever result (a+b) is can never be greater than UINT_MAX, because that would be a contradiction.

    You tried to use a bigger data type long to get around this, but this is actually not guaranteed to be bigger than int in C++. You may want to try long long instead (although this type does not exist in standard C++).

    Unlike, say, Java, C++ does not actually specify how large each data type must be, so the claim that UINT_MAX=65535 is not universally true. It’s only true for processors where an unsigned integer is held in 16 bits. For 32 bits, UINT_MAX is 4294967295.

    Related questions

    • Best way to detect integer overflow in C/C++

    See also

    • Wikipedia/Limits.h
    • cplusplus.com/reference/library/climits
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Best way to get identity of inserted row? When is it appropriate
Possible Duplicate: What is the best way to slurp a file into a string
Possible Duplicate: What is the best way to build XML in C# code? what's
Possible Duplicate: What's the best way to do a bulk namespace rename on a
Possible Duplicate: What's the best way to make a deep copy of a data
Possible Duplicate: What's The Best Way of Centering a Div Vertically with CSS .title_text_only{
Possible Duplicate: Efficient way to implement singleton pattern in Java I was reading this
Possible Duplicate: More efficient way of updating UI from Service than intents? I have
Possible Duplicate: Best method to parse various custom XML documents in Java HI all,
Possible Duplicate: Location detecting techniques for IP addresses For our website it's important to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.