1

Beginner here who is trying to read https://docs.soliditylang.org/en/latest/control-structures.html#default-value about default values of data types.

While all the other default data types described in this paragraph make sense to me, I cannot get my head around the statement,

"For statically-sized arrays and bytes1 to bytes32, each individual element will be initialized to the default value corresponding to its type."

Thus, as per the title: What is the default values of bytes1 to bytes32?

And any guidance on how to wrap my head around this, beyond a direct answer, is appreciated.

2 Answers 2

1

In Solidity, the default values of bytes1 to bytes32 types are arrays of bytes where each byte is initialized to 0x00.

Here are the default values for each of these types:

bytes1: 0x00
bytes2: 0x0000
bytes3: 0x000000
bytes4: 0x00000000
...
bytes32: 0x0000000000000000000000000000000000000000000000000000000000000000

So, for any bytesN type (where N is between 1 and 32), the default value is an array of N bytes, all set to 0x00.

2
  • Thanks Syed, that's much clearer. I can understand this, cheers.
    – Kojrey
    Commented Jul 17 at 2:39
  • You're welcome, @Kojrey. Happy coding! Commented Jul 17 at 3:02
1

0 (zero) is the default values of bytes1 to bytes32.

There are many ways zero can be written, like 0.0 (1 decimal place) or 00 (2 digits).

Table in @Syed's answer is a way you can think of it. But they are not an "array of bytes": bytes2 is just a number that can fit in 2 bytes, and so on.

As an analogy, you can think of bytes1 to bytes32 as boxes of different sizes. But each is only 1 box.

An array of bytes would be something like bytes1[2]: here you have 2 of the smallest-sized box.

2
  • Thanks @eth that adds to my understanding even more. This is appreciated, cheers!
    – Kojrey
    Commented Aug 3 at 23:03
  • You're welcome. Good luck with learning computer science and Ethereum can help improve / deepen understanding some parts of CS.
    – eth
    Commented Aug 9 at 0:53

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.