0

I was reading this article : https://www.geeksforgeeks.org/cpp-modifier-types/

There it was mentioned that long int is used to store large integer values, and I know the size of int is 4 bytes. In the article, the size of long int was 8 bytes, which made sense. But when I tried to use sizeof() in Visual Studio, I got the size of both int and long int as 4.

Also, it was written in the article that long long is used to store even larger integers, so I expected it to be 16 bytes, but both the article and Visual Studio say it's 8 bytes.

What is happening?

Also, why can char be unsigned? I mean, according to the ASCII table, all characters are assigned non-negative numbers, so when will char store negative numbers?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 6
    That website is not exactly known for being the most precise about C++. C++ does not specify the exact sizes of its fundamental types, [only minimal](https://en.cppreference.com/w/cpp/language/types) - the link will also answer all your questions. There are no 128bit integers in C++ due to little or no HW support. – Quimby Jun 29 '22 at 06:31
  • Fyi, MS toolchain, [`long int` is 32 bits wide](https://learn.microsoft.com/en-us/cpp/cpp/data-type-ranges?view=msvc-170), even on x64. – WhozCraig Jun 29 '22 at 06:32
  • 6
    The whole article is terrible. There is pretty much not a single sentence that does not need significant corrections in it. – user17732522 Jun 29 '22 at 06:36
  • 1
    On Windows `long int` is 4 bytes. On Unix based systems such as Linux and MacOS it is 8 bytes. And on some other platform it might be different. C++ allows the compilers to specify sizes however they want. So for example on a platform a `short int` can be 16 bytes (however this is practically meaningless and there's no such platform yet). – digito_evo Jun 29 '22 at 06:37
  • 2
    Better to use fixed size types where it matters. `int32_t`, `int64_t`, etc. – Retired Ninja Jun 29 '22 at 06:44
  • Thank you all, I now understand that C++ only specifies minimum size. – Neeladri Reddy Jun 29 '22 at 07:06
  • 2
    That article is bad even by geeksforgeeks standards. Stay away from that site. – molbdnilo Jun 29 '22 at 07:39
  • @NeeladriReddy On a side note, you are asking 2 completely unrelated questions. Please limit yourself to one question per post. You should delete the portion about chars and ask that separately. – Remy Lebeau Jun 29 '22 at 08:22
  • Learning C++ from GeeksForGeeks is like learning mathematics from sudoku puzzles. – Eljay Jun 29 '22 at 11:08

0 Answers0