mercredi 27 avril 2016

Is if statement optimized to not call recursive functions if first condition is false?

Consider the scenario:

int fun(node* a, node* b){
    if(a == NULL && b == NULL) return 0;
    if( (a->data == b->data) && (fun(a->left) == fun(b->left)) && (fun(a->right) == fun(b->right)) return 1;
    return 0;
}

If we met a condition like if a->data != b->data, then will the recursive call be made to (fun(a->left) == fun(b->left)) and (fun(a->right) == fun(b->right)) or will it directly say false for the condition?

Aucun commentaire:

Enregistrer un commentaire