-1
$\begingroup$

In Programming there is different data types (int , cahr , bool , float ) and they have different sizes (1,2,4,8 .. Bytes) , and the size of data type are depends upon hardware or architecture of computer or any thing else? as a beginner give me answer in simple language plz !

$\endgroup$
7
  • 2
    $\begingroup$ Why is the entire text of the question in a quotation block? What is that intended to convey? $\endgroup$
    – D.W.
    Feb 14, 2022 at 22:44
  • $\begingroup$ On recent machines, you can rely on the following rules: int might still be 16 bits on some low end processors (corresponding to register size), but in general, is 32 bits. int remains stuck at 32 bits, even on 64 bits machines. char will remain an 8 bit byte (ANSI character set), the smallest addressable data chunk, like bool. float 32 bits, double 64 bits, following IEEE standards. $\endgroup$
    – user16034
    Mar 16, 2022 at 15:46
  • $\begingroup$ @YvesDaoust : it depends upon 32 bit compiler or 64 bit compiler. ? $\endgroup$
    – Hamza
    Mar 17, 2022 at 15:16
  • $\begingroup$ What data type ? $\endgroup$
    – user16034
    Mar 17, 2022 at 15:30
  • 2
    $\begingroup$ @Dmitry, thanks! Unfortunately I don't have access to edit that (it is Stack Exchange wide, I think), but you could post that suggestion on Meta Stack Exchange if you wanted. $\endgroup$
    – D.W.
    Jul 14, 2022 at 17:51

2 Answers 2

0
$\begingroup$

In C, C++ and some other languages, char, signed char, and unsigned char are one byte by definition. A byte is whatever the type char is. It's like asking "how long is a meter" and I answer "exactly one meter".

The size of these types depends on the compiler. First, the language gives a definition what the types are capable of doing. For example, unsigned char is "at least 8 bit, supporting values from 0 to at least 255". A signed integer in C is "at least 16 bits, capable of representing at least values from -32767 to +32767". It could be 16 bits. In that case, a byte is 16 bits. (An "octet" is the name for a byte that is eight bits. A byte isn't required to be an octet). The compiler writer then looks at the hardware, and decides what number of bits would be best for some type. One restriction is the size must be a multiple of a byte - you can't have 8 bit char and 30 bit int. You could have 10 bit char and 30 bit int; that would be unusual but allowed. The size in bytes is obviously less if a byte is bigger, a 32 bit int can be four 8-bit bytes or two 16-bit bytes.

$\endgroup$
4
  • $\begingroup$ okk but most of peoples tell me its size is also depend upon data bus , address etc ? then what is mean by this . $\endgroup$
    – Hamza
    Feb 15, 2022 at 6:29
  • $\begingroup$ My computer has a 128 bit bus. The sizes don't depend on data bus etc. , but on the compiler. Obviously the compiler will take all kinds of things into account to determine what the best sizes are. In the end, what the compiler says goes. $\endgroup$
    – gnasher729
    Feb 15, 2022 at 18:12
  • $\begingroup$ i agree butt :The size of data type int is 2 byte in 32 bit architecture or 4 bytes in 64 bit architecture. .. what is this ? $\endgroup$
    – Hamza
    Feb 16, 2022 at 13:45
  • $\begingroup$ No, the size of data is what the compiler says it is. The compiler decides. Of course a reasonable compiler writer will make decisions that work well with the actual hardware, but the size is what the compiler says. $\endgroup$
    – gnasher729
    Mar 16, 2022 at 18:47
0
$\begingroup$

Compiler, if supported by the hardware but it is all based upon architecture and design of the machine.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.