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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:54:01+00:00 2026-05-31T00:54:01+00:00

I expected that the size will be different. But both are showing 8bytes. #include

  • 0

I expected that the size will be different. But both are showing 8bytes.

#include <iostream>
using namespace std;
int main()
{
    cout<<"Size of long:"<<sizeof(unsigned long)<<"\n";
    cout<<"Size of Long Long:"<< sizeof(unsigned long long)<<"\n";
}

Output:
Size of long:8
Size of Long Long:8
  • 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-31T00:54:02+00:00Added an answer on May 31, 2026 at 12:54 am

    They’re two distinct types, even if they happen to have the same size and representation in some particular implementation.

    unsigned long is required to be at least 32 bits. unsigned long long is required to be at least 64 bits. (Actually the requirements are stated in terms of the ranges of values they can represent.)

    As you’ve seen, this is consistent with them both being the same size, as long as that size is at least 64 bits.

    In most cases, the fact that they’re distinct types doesn’t matter much (except that you can’t depend on them both having the same range of values). For example, you can assign an unsigned long long to an unsigned long object, and the value will be converted implicitly, possibly with some loss of information. Similarly, you can pass an unsigned long long argument to a function expecting an unsigned long (unless the function is variadic, like printf; then an explicit conversion is needed).

    But one case where it does matter is when you have pointers. The types unsigned long* and unsigned long long* are not just distinct, they’re not assignment-compatible, because there is no implicit conversion from one to the other. For example, this program:

    int main()
    {   
        unsigned long*      ulp  = 0;
        unsigned long long* ullp = 0;
        ulp = ullp; // illegal
    }
    

    produces the following when I compile it with g++:

    c.cpp: In function ‘int main()’:
    c.cpp:5:11: error: cannot convert ‘long long unsigned int*’ to ‘long unsigned int*’ in assignment
    

    One more difference: the C++ standard didn’t add the long long and unsigned long long types until 2011. C added them with the 1999 standard, and it’s not uncommon for pre-C++2011 (and pre-C99) compilers to provide them as an extension.

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

Sidebar

Related Questions

Today I've a weird question. The Code(C++) #include <iostream> union name { int num;
I'm creating a JavaScript class (using Prototype) that will set the page state to
I have a Rails app implementing a game, so it's expected that a player
Is it expected behavior that two encodings can map to the same decoding? I'm
I have a method fetchObjects(String) that is expected to return an array of Contract
I know that one can define an 'expected' exception in JUnit, doing: @Test(expect=MyException.class) public
I am trying to test that a particular method throws an expected exception from
I've heard many people say that if the number of expected elements in the
I have the following bit of code that worked as expected before we upgraded
I expected the following code to print 8, 111 and 999. I supposed that

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.