Skip to Content
Mastering Blockchain Programming with Solidity
book

Mastering Blockchain Programming with Solidity

by Jitendra Chittoda
August 2019
Intermediate to advanced
486 pages
13h 52m
English
Packt Publishing
Content preview from Mastering Blockchain Programming with Solidity

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Ethereum

Mastering Ethereum

Andreas M. Antonopoulos, Gavin Wood
Complete Cryptocurrency and Blockchain Course | Learn Solidity

Complete Cryptocurrency and Blockchain Course | Learn Solidity

Ravinder Deol, Codestars By Rob Percival, Thomas Wiesner

Publisher Resources

ISBN: 9781839218262Supplemental Content