Search code examples
c++nullbitwise-operatorsnullablebit-shift

Can Bitwise Operation on NULL value crash the code in C++


It seems that my program crashes on this line where im doing some bitwise operation on "a" array filled with NULL values (empty array), can this be a cause to program crash?

const unsigned char a [ something ];
int b;
b = (a[0] & 0x0f) << 8; 

Solution

  • No, the code below

    const unsigned char a [ something ];
    int b;
    b = (a[0] & 0x0f) << 8; 
    

    by itself cannot cause your program to crash. Something else is wrong with your code.