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 6933631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:51:26+00:00 2026-05-27T11:51:26+00:00

On Visual Studio 2010 the following program #include <iostream> using std::cout; int main() {

  • 0

On Visual Studio 2010 the following program

#include <iostream>
using std::cout;

int main()
{
    cout << -2147483646 << '\n';
    cout << -2147483647 << '\n';
    cout << -2147483648 << '\n';    // numeric_limits<int>::min()
    cout << -2147483649 << '\n';
    cout << -2147483650 << '\n';
    cout << "..." << '\n';
    cout << -4294967293 << '\n';
    cout << -4294967294 << '\n';
    cout << -4294967295 << '\n';    // -numeric_limits<unsigned int>::max()
    cout << -4294967296 << '\n';
    cout << -4294967297 << '\n';
}

generates the following output

-2147483646
-2147483647
2147483648
2147483647
2147483646
...
3
2
1
-4294967296
-4294967297

What is going on?

Is this standard behavior or a Visual Studio bug?

Edit: As several people have pointed out, there is no such thing as a negative integer literal. See Keith Thompson’s excellent answer below for more details.

  • 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-27T11:51:27+00:00Added an answer on May 27, 2026 at 11:51 am

    -2147483648, for example, is not an integer literal. It’s an expression consisting of a unary - operator applied to the literal 2147483648.

    Prior to the C++ 2011 standard, C++ didn’t require the existence of any type bigger than 32 bits (C++2011 added long long, which is at least 64 bits), so the literal 2147483648 was non-portable.

    A decimal integer literal is of the first of the following types in which its value fits:

    int
    long int
    long long int (C++ 2011 and later)
    

    Note that it’s never of an unsigned type in standard C++. In pre-2011 editions of the C++ standard (which didn’t have long long int), a decimal integer literal that’s too big to fit in long int resulted in undefined behavior — but you’re unlikely to have to worry about that. In C++2011 and later, if a decimal integer literal doesn’t fit in long long int, then the program is "ill-formed".

    Some very old versions of g++ didn’t implement the C++2011 semantics. For example, g++ 4.6.1 (the version on which I based the original version of this answer) treated the literal 2147483648 as a constant of type unsigned long. (See the edit history of this question for more out-of-date information.)

    Here’s a small program that you can use to show how your compiler treats literals:

    #include <iostream>
    #include <climits>
    
    const char *type_of(int)                { return "int"; }
    const char *type_of(unsigned int)       { return "unsigned int"; }
    const char *type_of(long)               { return "long"; }
    const char *type_of(unsigned long)      { return "unsigned long"; }
    const char *type_of(long long)          { return "long long"; }
    const char *type_of(unsigned long long) { return "unsigned long long"; }
    
    int main()
    {
        std::cout << "int: " << INT_MIN << " .. " << INT_MAX << "\n";
        std::cout << "long: " << LONG_MIN << " .. " << LONG_MAX << "\n";
        std::cout << "long long: " << LLONG_MIN << " .. " << LLONG_MAX << "\n";
    
        std::cout << "2147483647 is of type " << type_of(2147483647) << "\n";
        std::cout << "2147483648 is of type " << type_of(2147483648) << "\n";
        std::cout << "-2147483647 is of type " << type_of(-2147483647) << "\n";
        std::cout << "-2147483648 is of type " << type_of(-2147483648) << "\n";
    }
    

    When I compile and execute it (with g++ 11.3.0 on 64-bit Ubuntu) I get:

    int: -2147483648 .. 2147483647
    long: -9223372036854775808 .. 9223372036854775807
    long long: -9223372036854775808 .. 9223372036854775807
    2147483647 is of type int
    2147483648 is of type long
    -2147483647 is of type int
    -2147483648 is of type long
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried the following program on Visual Studio 2010. #include <iostream> using namespace std;
I have following code: #include <iostream> using namespace std; template<class T> T max(T *data,int
When I try to compile the following C++ program using the Visual Studio 2010
I'm having the following problem using the Visual Studio 2010 Team System Beta 1:
If I install Visual Studio 2010 Ultimate (x86) - DVD (English) Are the following
Do visual studio 2010 include already Sql Server instance, or I need to install
Problem Description: Occassionally when debugging, I get the following error. I'm using visual studio
The following snippet fails to compile with Visual Studio 2010, but GCC likes it:
I tried to have Visual Studio 2010 create unit tests for the following class,
After following guide on how to compile QT with Visual Studio 2010 I still

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.