We,all know the importance of functions in C. And any good-programmer will be using well coded functions in his program, may be including them in a loop as well.But, while using the function in a nested if else we must be careful and should keep in mind the output of the function and what exactly do we want.I am saying this because my program returned insane values due to a careless use of functions.
The problem causing bit of code is here:
if(strt < insert(strt,end,value)
{
//some stuff;
}
else if(strt == insert(strt,end,value)
{
//some stuff;
}
what happened here was that, for the 1st if statement the function insert was called. Now suppose the value is false and the other if statement is to be implemented, then it will again call the insert function which is not how it should happen because for the new function, it will find a new value instead of the old value. So, it is better to store the value of the function and compare the stored value.
Lets hope that we don't make this mistake again. : )
Tweet
No comments:
Post a Comment