Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

long long might not store integer?

Tags:

c++

In my assignment, it says "Do not add long int or long long private members to accomplish this as there is no guarantee that either can actually store larger numbers than an int." I know that int has a maximum of 2^31-1 and long long has a maximum of 2^63-1. So can someone give me an example to me why the given sentence is true?

Thanks in advance!

like image 684
user44322 Avatar asked Jan 16 '23 00:01

user44322


1 Answers

It means exactly what it says. There's no guarantee that a long long can store more numbers than an int. It's at least as big, but it can be the same.

I know that int has a maximum of 2^31-1 and long long has a maximum of 2^63-1

This can be true for some platform, with some compiler, but it's not always the same. C++ doesn't guarantee either.

3.9.1 Fundamental types [basic.fundamental]

2) There are five standard signed integer types : “signed char”, “short int”, “int”, “long int”, and “long long int”. In this list, each type provides at least as much storage as those preceding it in the list. [...] (emphasis mine)

like image 95
Luchian Grigore Avatar answered Jan 24 '23 21:01

Luchian Grigore