mardi 29 septembre 2020

if flag = 0, then which will be the most preferable statement to execute the true or false block? if(!flag) or if(flag == 0)

In the code given here:

void search(int a)
{
    int i = 0, flag = 1;
    for(; i < MAX; i++)
    {
        if(a == stack[i])
        {
            flag = 0;
            break;
        }
    }

    if(!flag)
        printf("%d found at location %d.\n", a, i);
    else
        printf("%d not found in the stack.\n", a);
    return;
}

which statement if(!flag) or if(flag == 0) will be more efficient and generalized? Is using if(!flag) considered as a wrong approach?

Aucun commentaire:

Enregistrer un commentaire