Skip to content

Instantly share code, notes, and snippets.

@ArslanKathia
Created January 26, 2023 17:28
Show Gist options
  • Save ArslanKathia/9770f5c58face4b8901c6260c3fb9c35 to your computer and use it in GitHub Desktop.
Save ArslanKathia/9770f5c58face4b8901c6260c3fb9c35 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=
//SPDX-License-Identifier: MIT
pragma solidity ^0.8;
contract fixedSizeArray{
uint[5] public arr = [10,20,30,50,70];
uint[10] arr2;
uint[5] public arr3;
constructor(){
arr3 = [100,200,300];
}
function arrayTest() public returns(uint){
// uint[] memory array4 = new uint[](3); //local varuable
uint temp;
temp = arr[2];
arr[2] = 1000;
delete arr[4];
return temp;
}
function arrayTest2(uint _x) public returns(uint[10] memory){
//in function we can used only fixed size array array
for(uint i=0;i<arr2.length;i++){
arr2[i] = _x*i;
}
return arr2;
}
function getArray2() public view returns(uint[10] memory){
return arr2;
}
function getArray() public view returns(uint[5] memory){
return arr;
}
function getArray3() public view returns(uint[5] memory){
return arr3;
}
function setArray3(uint _index,uint _value) public returns(uint[5] memory){
arr3[_index]= _value;
return arr3;
}
function deleteArray3(uint _index) public returns(uint[5] memory){
delete arr3[_index];
return arr3;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment