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

  • SEARCH
  • Home
  • 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 6548231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:55:36+00:00 2026-05-25T11:55:36+00:00

I ran the following two pieces of code on Windows XP (Code:Block, MinGW), and

  • 0

I ran the following two pieces of code on Windows XP (Code:Block, MinGW), and Ubuntu (11.04, G++)

I have trouble running the following code

#include <iostream>

using namespace std;

int main(){

    long long a = 9223372036854775807;
    cout <<  a;
    return 0;

}

That number is 2^63 -1. But I will get an error stating:

C:\Documents and Settings\JohnWong\My
Documents\codeblock\343_hw_1\main.cpp|9|error: integer constant is too
large for “long” type|

On ubuntu – it compiled, but the answer retunred is 9223372036854775808, notice the 8 at the end….

Now if I run this code, using the power function, I am okay.

#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

int main(){

    long long a = pow(2,64);
    cout << "a:   " << setprecision(20) << a << endl;
    cout << "a-1:   " << setprecision(20) << a-1 << endl;
    cout << "a-2:   " <<  setprecision(20) << a-2 << endl;
    cout << "a+0:   " << setprecision(20) << a+0 << endl;
    cout << "a+1:   " << setprecision(20) << a+1 << endl;
    cout << "a+2:   " << setprecision(20) << a+2 << endl;
    cout << "a+3:   " << setprecision(20) << a+3 << endl;

    return 0;
}

I will get the values I want (anything from +1 will cause an overflow, that’s okay).

On Ubuntu the outputs looks the same. Good.

So what’s going on here? Why constant is not good???
I even tried intmax_t and int64_t as datatype running the first code.

Can someone explain this behavior? Thanks!

  • 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-25T11:55:36+00:00Added an answer on May 25, 2026 at 11:55 am
    long long a = 9223372036854775807LL;
    

    The LL makes the literal a long long literal. Otherwise the literal defaults to being a long literal and then is casted over to a long long before being stored in a.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following two loops: #include <iostream> #include <stdlib.h> #include <time.h> using namespace
I ran the following code, but nothing came up on the console.... #include <stdio.h>
I have the following code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using
I have the following C++ program and ran it using Visual Studio 2008 on
We have few components like libraries dlls When initially created I ran the following
I ran across the following code in Ely Greenfield's SuperImage from his Book component
I ran across the following code in one of our in-house dlls and I
Today I ran into the following problem with NUnit. I have a class, that
I merged the wrong way between two branches. I then ran the following: git
I'm also using Capybara. I have a bunch of test cases.. and two of

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.