-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path19_DataLocation.sol
34 lines (26 loc) · 910 Bytes
/
19_DataLocation.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract DataLocation{
/* Data Locations:
When we use a Reference data type, we also need to specify the data location. 👇
( ☝ structs, arrays and mapping )
- storage : Location type for storing state variables which means data will be persisted.
- memory : To hold the value onto memory.
- calldata : Similiar to memory but this can only be used with function inputs.
*/
struct Asset{
uint assetId;
string name;
}
Asset public asset; // Stored in the storage
function operation() external returns (Asset memory){
// Asset is a struct that's why we are using memory ☝
asset.assetId=1;
asset.name="ETH Documentation";
return asset;
}
function len(uint[] calldata _num) external pure returns (uint){
uint lenArray = _num.length;
return lenArray;
}
}