Im dealing with recursion in class right now and im not sure as to what this lin
ID: 3715833 • Letter: I
Question
Im dealing with recursion in class right now and im not sure as to what this line does can sone one help thanks. return k > 0 ? k + sum(k - 1) : 0;
Explanation / Answer
k > 0 ? k + sum(k - 1) : 0; This is a ternary operation ternary operation is in the form -> condition ? expression1 : expression2 if condition evaluates to true, then expression1 is executed if condition evaluates to false, then expression2 is executed return k > 0 ? k + sum(k - 1) : 0; This statement returns value of "k + sum(k - 1)" if "k > 0" is true This statement returns value of 0 if "k > 0" is false Hope it's clear If it's not, please let me know and please upvote this answer. Thank you!