Variables of greater size?

I understand that the majority of variables will work for the job within their current restrictions. However, there may be the rare case that, say, an integer will need to surpass 4,294,967,296. Yes, such a case would be rare, but it would be helpful to know that it's possible. Apologies for such a beginner question, but I happen to be a beginner in C++.

TL;DR: I would like to know how/if it's possible to create a variable with a byte-size of my own specification for variables that surpass the normal limits. Thanks for any responses, they are much appreciated.
When you find that the existing primitives don't meet your needs, you need to create new ones yourself (or get a library from someone else who has already done so). In C++, these new types are called classes (or structures).

The case you describe above requires what is usually known as a "bignum" library; for example, the The GNU MP Bignum Library, which contains types capable of representing greater values. You certainly can do it yourself rather than use a library, and there is a lot to be learned in doing so.
Last edited on
Thank you for the response. I am aware of how classes work, as I have recently completed a course on Java and have read through to chapter 15.4 on http://www.learncpp.com

Thank you for the reference to GNU MP, it seems to be able to handle the functionality I was hoping for. I'll see what I can do as far as creating my own classes to do this sort of thing, but it just seems like an extra hassle, having been made aware of this library.

Thanks again for the help. :)
Last edited on
I think with C++11
you can write

unsigned long long big = 4294967296 ;
cout << big << endl ;

then it should work.
i think unsigned long long is the largest restriction. I tried your number and some greater numbers and it worked.
That should prove to be helpful as well. Thank you for the contribution.
Topic archived. No new replies allowed.