LEARN SOLIDITY LESSON
Math Operations. Structs. Arrays in solidity
Math Operations in Solidity
Math in Solidity is pretty straightforward. The following operations are the same as in most programming languages:
pragma solidity >=0.5.0 <0.6.0; contract HelloWorld {
uint x2 = 5 + 2; //= 7
uint x1 = 5 ** 2; //5^2 = 25
uint x2 = 13 % 5; //= 3
}
Structs and Arrays in Solidity
Structs
Structs allow you to create more complicated data types that have multiple properties.
struct Person { uint age; string name; }
Arrays
When you want a collection of something, you can use an array. There are two types of arrays in Solidity: fixed arrays and dynamic arrays:
uint[2] fixedArray;
string[5] stringArray; uint[] dynamicArray;
struct Person { uint age; string name; }
Person[] people;
Structs and Arrays
struct Person { uint age; string name; }
Person[] public people;
Person satoshi = Person(172, "Satoshi"); people.push(satoshi);
Comments