Created
August 4, 2022 14:16
-
-
Save mengsina2014/24668b1e3aca3afd7a80ba47162955f0 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.4; | |
contract Array_5{ | |
uint[9] array1; | |
//bytes[20] array2; | |
address[100] array3; | |
uint[] array4; | |
// byte[] array5; | |
address array6; | |
bytes array7; | |
//public private internal extranal ,修改方法的可见性的 | |
//pure 不能读,不能写合约变量,view 能读不能写合约的变量,payable 读取合约里面的值也能改写 | |
function test() public{ | |
uint[] memory array8=new uint[](5); | |
bytes memory array9 = new bytes(10); | |
array4 = new uint[](10); | |
array4.push(1); | |
} | |
struct Student{ | |
uint256 id; | |
uint256 score; | |
} | |
Student student; | |
function structA() external{ | |
//函数里面的storage student的修改,会影响合约里面的student | |
//如果都是storage的变量,就互相影响;都是memory的变量,也互相影响。因为传的是引用类型 | |
//storage 传给 memory,就是创建一个新副本,不会互相影响。 | |
Student storage _student = student; | |
_student.id = 1; | |
_student.score = 100; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment