'Why there's no concept of Null initialization to an unsigned integer in solidity?

I was writing a code my unsigned-integer value initialized as 0 as shown below

My code:

// SPDX-License-Identifier: UNLICENSED

pragma solidity >= 0.5.0 < 0.9.0;

contract PT_StateVariable

{

    uint256  public age ;
}

Deploy tab

But when I tried to give it a NULL, it gave an error.

Why there's no NULL concept (like in C++) been used in Solidity?



Solution 1:[1]

In Solidity doesn't exist the concept of 'NULL' like in C++,C#,Java,... The documentation say this:

The concept of “undefined” or “null” values does not exist in Solidity, but newly declared variables always have a default value dependent on its type. To handle any unexpected values, you should use the revert function to revert the whole transaction, or return a tuple with a second bool value denoting success.

I recommend you to read documentation's section about declarations:

A variable which is declared will have an initial default value whose byte-representation is all zeros. The “default values” of variables are the typical “zero-state” of whatever the type is. For example, the default value for a bool is false. The default value for the uint or int types is 0. For statically-sized arrays and bytes1 to bytes32, each individual element will be initialized to the default value corresponding to its type. For dynamically-sized arrays, bytes and string, the default value is an empty array or string. For the enum type, the default value is its first member.

More information here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kerry99