0

Say I have this C++ code (it's from a binary tree problem)

if(t->left != nullptr && t->left->data != t->data)

Isn't it problematic since I try to access possibly a nullpointer's data? Or does it work? because the boolean evaluation happens in a specific order.

fabian
  • 80,457
  • 12
  • 86
  • 114
SotirisD
  • 23
  • 2

1 Answers1

0

If the first condition results to false, the second one is not evaluated. So it's completely safe.

wuarmin
  • 3,274
  • 3
  • 18
  • 31