I remember reading that the correct way to check if an address is 0x0 or not is _addr == address(0) and not _addr == 0. However, I'm unable to find any difference between the two when I run the following:

pragma solidity ^0.4.19;

contract Test {
    bool public isResult1 = false;
    bool public isResult2 = false;

    function isAddressZero1(address _addr) public {
        isResult1 = (_addr == address(0));

    function isAddressZero2(address _addr) public {
        isResult2 = (_addr == 0);

Is there a known issue with _addr == 0 or is the explicit typecasting just to be safe?

  • 3
    Any of those are fine. I usually do _addr != 0x0 to make it easily identifiable in code. Dec 29, 2017 at 17:03

2 Answers 2


These should be completely equivalent. I think some people may prefer 0x0 or address(0) or address(0x0) as some sort of convention (to make it a little clearer what kind of 0 you mean), but they all should compile to the same thing.

Solidity Version 0.5.0 onwards, you cannot compare directly with 0 or 0x0 or "0" or "0x0". Since these types are not treated as address.

  • 4
    In Solidity version 0.5.0 ; comparing with integer 0 is not allowed anymore. Dec 8, 2018 at 11:26

In solidity 0.5 this is the correct way to compare addresses

require(address(_registry) != address(0));   

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.