Hay Dear!
i know that if statement is an expensive statement in c++. I remember that once my teacher said that if statement is an expensive statement in the sense of computer time.
Now we can do every thing by using if statement in c++ so this is very powerful statement in programming perspective but its expensive in computer time perspective.
i am a beginner and i am studying data structure course after introduction to c++ course.
my Question to you is
Is it better for me to use if statement extensivly?
I’m not sure how you can generalise that the if statement is expensive.
If you have
then this the
ifwill most likele be optimised away by your compiler.If, on the other hand, you have..
and the method
veryConvolutedMethodTogGetAnswer()does lots of work then, you could argue tha this is an expensive if statement but not because of the if, but because of the work you’re doing in the decision making process.“if”‘s themselves are not usually “expensive” in terms of clock cycles.