-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02_state.sol
32 lines (25 loc) · 929 Bytes
/
02_state.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
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract state {
uint256 public age;
// If we declare a state variable in the contract then we have to pay certain amount of gas.
// So we have to take care while declaring any variable, whether it is necesary or not.
// The default value for uint is 0.
// Writing public leads to the declaration of get function automatically for that variable.
// age=10 ......not allowed.
// constructor() public{
// age=10
// } .....allowed.
function setAge() public {
age = 10;
} //.....allowed
/*
To change default values of the state variables -
1) Using the contracts constructor.
2) Initializing the variable at declaration.
3) Using the setter function.
4) Permanantly stored in contract storage.
5) Cost gas(expensive).
6) Storage is not dynamically alllocated.
*/
}