+ 1

Hey can anyone tell me why i++ is not working on line no. 20

I+1 is working but I++ is not. What's the difference between them here. https://code.sololearn.com/cnPLtoAFlRus/?ref=app

13th Feb 2022, 4:05 AM
Raisun Lakra
3 ответов
+ 8
i++ adds 1 and stores it in i, while i+1 just output value i by 1 more. In general, "i" is not needed here ☺️: int largestElement(int a[],int size){ static int larg; if(a[size]>larg) larg=a[size]; if(size>1) largestElement(a,size-1); return larg; } And don't forget about #include <stdio.h>
13th Feb 2022, 6:26 AM
Solo
Solo - avatar
+ 6
If you use ++i (pre-increment operator) it works. If you use i++ (post-increment operator), value of <i> is not modified until the current line is completely processed. It's also great to understand the use case, where to use increment or decrement operator with a variable, and when to just add a value to a variable.
13th Feb 2022, 4:21 AM
Ipang
+ 5
raisun lakra Do ++i because i++ is post increment so 0, 0, 1, 2, 3 and on ++i , 0, 1, 2, 3
13th Feb 2022, 4:26 AM
A͢J
A͢J - avatar