Not related to this question ..i was just confused about this thing

how does || and && statement work?
suppose if(codnA || codnB )
if cod A is true will it also check codnB ,as it doesn’t even mater if it is true or not the final ans will be true because of codnA

and pls tell the same for && …
Thanks

hello @abhigyanprakash29 the first is OR operator and the second is the AND operator. In the OR operator the if either of the result evaluates to be true then the expression will come out to be true. but in the AND condition if any of the condition is false then the whole condition will be false.
so it is that in the OR operator even if any one condition is true then the full relation will become true.
whereas in AND if any of the condition is false then the full relation is false.
if you have any doubt you can ask here.
Happy Learning !!

i am aware of that pls read my question again…i want to will both comparisons will always be made …for both OR and AND

Yes i have told you this only.
that in the or only condition true will be fine so the result will be true .
As you have asled in the above question if codnA IS TRUE then the whole while loop condition will be true .
but the same is not true in the AND all the conditons should be true.
Happy learning !!

no suppose i am working on stack

@abhigyanprakash29 then what if you are working on stack?
AND will always be evaluate in the same way.

and if(stack.empty() || ( a[i] >stack.top()) …if the stack is empty will the top of stack be compared?(top which doesn’t exist and will show segmentation fault)…or whenever the stack.empty() is true it will never chechk the 2nd statement as it wont even matter if it is true or false…it will still go inside the loop

you are applying OR so no if the stack is empty then it will evaluate to be true .
but if you want every condition should be true only then it should run then you have to take AND.
it is simple.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.