Created
July 13, 2022 10:29
-
-
Save ashwinYardi/98ec7c904c87a1c03726d548fd235bfb to your computer and use it in GitHub Desktop.
Contract to demo reference typed data types in Solidity
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
// Solidity program to demonstrate | |
// reference types | |
pragma solidity ^ 0.8.5; | |
// Creating a contract | |
contract DemoReferenceTypes { | |
// Defining an array of fixed size | |
uint[5] public fixedSizeArray = [uint(1), 2, 3, 4, 5]; | |
// Defining a Structure | |
struct DemoStruct { | |
string firstVar; | |
address secondVar; | |
uint8 thirdVar; | |
} | |
// Creating a structure object | |
DemoStruct public struct1; | |
// Creating a mapping | |
mapping (address => DemoStruct) public sampleMapping; | |
address[] student_result; | |
constructor() { | |
struct1.firstVar = "abcd"; | |
struct1.secondVar = address(0x0); | |
struct1.thirdVar = 1; | |
sampleMapping[address(0x10)] = struct1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment