Resetting variables using the delete keyword

The delete keyword is used to reset the values of some data type and complex types such as arrays and structs. For example, if delete is used on int/uint, its value will be set to 0, which is the default value of the data type:

uint a = 1;
function reset() public {
delete a; //resets the value of a = 0
}

In the same way, delete can also be used to reset the array types, where it assigns a dynamic array of length 0 if the array is a dynamic array. If an array is a static array, it resets all elements and keeps the length of the array same.

When the delete keyword is used for a struct, it resets all of the variables of the struct to their respective default values.

For mappings, you can reset a value by calling delete on its key. One thing to notice here is that delete a behaves like an assignment to the a variable; it restores the default value of the type.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.76.12