Skip to content

Lesson 2: Array are not clear #2597

Answered by alymurtazamemon
Salutix asked this question in Q&A
Discussion options

You must be logged in to vote

@Salutix Hey! These both are different things but because the symbol is the same that is why it is confusing you. Let me clear it up!

uint256 arrayName[3];

Here this [ ] symbol we use to create a fixed-size array. It indicates the length of the items it can contain.

nameToFavoriteNumber[_name] = _favoriteNumber;

But here [ ] this symbol has a different meaning, nameToFavoriteNumber is a mapping. The mapping you can think of it as a key/value pair (key => value). And it does not link 1 key with multiple values, it only links 1 key with 1 value.

So here what we are doing is that every time we call the addPerson function and pass name and favoriteNumber, It will do two 2 things, 1. It will c…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Salutix
Comment options

@alymurtazamemon
Comment options

@Salutix
Comment options

Answer selected by Salutix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants