having trouble finding this anywhere, on a 32bit computer, how many bytes does it take to store ; long int, unsigned char,float, double
any help is much appreciated

Dani AI

Generated

Short answer (typical on 32‑bit ILP32 systems): long int = 4 bytes, unsigned char = 1 byte, float = 4 bytes, double = 8 bytes. That matches ’s common-size list, but it is not a language guarantee — as pointed out the exact sizes are implementation dependent.

Why that matters: the C/C++ standard only guarantees sizeof(char) == 1 (a “byte” in C/C++ terms) and ordering constraints:

  • sizeof(short) >= sizeof(char)
  • sizeof(int) >= sizeof(short)
  • sizeof(long) >= sizeof(int)
  • sizeof(long long) >= sizeof(long)

sizeof(T) returns the number of char-sized bytes; CHAR_BIT (in <climits>) gives the number of bits per char (commonly 8). unsigned char’s range is 0..(2^CHAR_BIT - 1). char signedness is implementation-defined, so use unsigned char or std::uint8_t for raw bytes.

Quick compile/run checker (prints bytes and bits):

#include <iostream>
#include <climits>
#include <cstdint>

template<class T>
void show(const char* name) {
    std::cout << name << ": " << sizeof(T) << " byte(s), "
              << sizeof(T)*CHAR_BIT << " bit(s)\n";
}

int main() {
    show<unsigned char>("unsigned char");
    show<long>("long");
    show<float>("float");
    show<double>("double");
}

Practical notes: prefer fixed-width types (<cstdint>) when an exact size is required. Floating-point sizes are almost always 32/64 bits for float/double on modern compilers, but long changes across platforms (e.g., LP64 on Unix: long is 8 bytes; LLP64 on Windows: long is 4 bytes). Also: the correct term is “byte” (not “bite”), as noted. ’s suggestion to check sizeof on the target system is the definitive approach.

Recommended Answers

All 4 Replies

long int - 4 bytes
char/unsigned char - 1 byte
float - 4 bytes
double - 8 bytes

The same for x64.

This is a very simple question you might have easily looked up from a search engine
you might consider that next time ;)

http://msdn.microsoft.com/en-us/library/s3f49ktz(v=vs.71).aspx

(edit) for the record the term is "Byte" as opposed to "Bite".
(edit2) it also might vary on how many bytes are actually used, depending on your compiler.

having trouble finding this anywhere, on a 32bit computer, how many bytes does it take to store ; long int, unsigned char,float, double

You're having trouble finding it because there's no absolute answer. Only char has a guaranteed size (it's always going to be 1), the rest are implementation dependent (though nullptr listed common sizes on a 32-bit implementation).

Of course, on any given system (OS + compiler) on which you work, you can check the size of each data type with the sizeof( ) operator.

cout << sizeof( int );  //repeat for each type you're interested in.

The sizes that were given above are quite common. You'll most often find differences in the long double type.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.