Answer the question
In order to leave comments, you need to log in
What to choose: clarity or brevity of logical conditions?
There are two options for writing boolean conditions with pointers in C++
1)
while (a_ptr || b_ptr) {
uint currentDataA = (a_ptr) ? a_ptr->data : 0;
uint currentDataB = (b_ptr) ? b_ptr->data : 0;
....
}
while (a_ptr != nullptr || b_ptr != nullptr) {
uint currentDataA = (a_ptr != nullptr) ? a_ptr->data : 0;
uint currentDataB = (b_ptr != nullptr) ? b_ptr->data : 0;
....
}
Answer the question
In order to leave comments, you need to log in
Explicit is better than implicit.
Code is more often read than written.
So the second option is better.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question