0

I have a mapping between an address and an array of structs like this...

struct myStruct{
    string name,
    uint height
}

mapping (address=>myStruct[]) myMapping

if I access myMapping with an address key that hasn't been seen before, what gets returned?

e.g.

x = myMapping["unknownKey"];

What is in x? Is it 0 or [] or something else?

Simon
  • 197
  • 1
  • 1
  • 6

2 Answers2

1

Quoting from solidity docs:

A variable which is declared will have an initial default value whose byte-representation is all zeros. The “default values” of variables are the typical “zero-state” of whatever the type is. For example, the default value for a bool is false. The default value for the uint or int types is 0. For statically-sized arrays and bytes1 to bytes32, each individual element will be initialized to the default value corresponding to its type.

For dynamically-sized arrays, bytes and string, the default value is an empty array or string. For the enum type, the default value is its first member.

https://docs.soliditylang.org/en/v0.8.13/control-structures.html#default-value

So, it should be an empty array.

Meet
  • 326
  • 1
  • 4
0

If the value for a specific key provided to a mapping doesn't exist, then it will hold a false value, in this case an empty array.

Sumit Banik
  • 101
  • 1