1
int* ptr;
//ptr may points to any location(e.g. nullptr)
if(ptr != nullptr && *ptr != 1) {
  //A
} else {
  //B
}

so are the above codes always equivalent to the following ones?

if(ptr != nullptr) {
  if(*ptr != 1) {
    //A
  } else {
    //B
  }
} else {
  //B
}

I wonder if this rule a standard or implementation-defined, and is the first piece of code portable?

Frahm
  • 805
  • 2
  • 9
  • 16

0 Answers0