Post/Pre Increment/Decrement ---------------------> Boon or Curse!
Ah, so, We love Increment/Decrement operators ( well most of us ), don't we?? Be Cautious while using INCREMENT/DECREMENT operators when: 1) While Giving ARGUMENTS to a RECURSIVE FUNCTION: Let's take an example of a recursive factorial() int fact(int n) { if(n==1) return 1; return n*fact(n--); } The above function may look straightforward but, the above function will call itself infinitely. Why? We have used post decrement ( -- ) while passing value to fact(). Lets recall, how does POST DECREMENT work? --> It first assigns the value then decrement occurs. so, we actually passed N instead of ( N-1 ) in argument, thus resulting in infinite recursion. We can instead use PRE DECREMENT OPERATOR. Note: NEVER USE POST DECREMENT/INCREMENT OPERATORS while passing values to a function. 2) Don't use POST/PRE INCREMENT OPERATORS at all, when the recursion is not tail recursion: Consider the below two functions: int calc1(int a,int b) { if(a>b) retu