can any one answer y cant we use decrement operator (x--) as a argument while calling a function recursively..? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

can any one answer y cant we use decrement operator (x--) as a argument while calling a function recursively..?

3rd Jun 2017, 2:33 AM
vinay lingam
vinay lingam - avatar
3 Answers
+ 4
You can, it just wont pass in the correct value. --x will however. Thats because the value of x AFTER the operation is passed in, unlike x-- where the value of x is passed in before the operation
3rd Jun 2017, 2:39 AM
aklex
aklex - avatar
+ 1
thanx aklex youre ans helped me a lot..
3rd Jun 2017, 2:41 AM
vinay lingam
vinay lingam - avatar
+ 1
@aklex sorry i need to correct you, but the operation is actually always evaluated before the function call in both cases. the difference is that the postfix implementation is coded to make a temporary copy, alter the value and then return the temp var. thats why you should rather use the prefix ++ then the postfix to prevent unnecessary copies!
3rd Jun 2017, 11:25 AM
Rob Sommerer, MSc
Rob Sommerer, MSc - avatar