+ 2

Why we use i++,+i and --i

30th Jun 2020, 8:15 AM
Umais Khan
Umais Khan - avatar
23 Answers
+ 4
Mahmud Nabil In fact I am not sure about it. It was just told me by someone i trust😬 He told me something like this: Moreover, modern CPUs are highly complex beasts, which can execute a lot of operations in parallel, and quite often, "simple" operations like these can be entirely hidden by running them in parallel with larger, more complex ones. I found this on: https://stackoverflow.com/questions/6889647/is-there-any-performance-difference-with-i-vs-i-1-in-c
30th Jun 2020, 12:01 PM
Alexander Thiem
Alexander Thiem - avatar
30th Jun 2020, 8:27 AM
Sandra Meyer
Sandra Meyer - avatar
+ 3
I didn't say anything else, I posted a link with a correct description of these operators.
30th Jun 2020, 8:32 AM
Sandra Meyer
Sandra Meyer - avatar
+ 3
Alexander Thiem I've doubts about the time efficiency thing you mentioned. Whould you provide some references?
30th Jun 2020, 11:50 AM
Mahmud Nabil
Mahmud Nabil - avatar
+ 3
If i=1 and we use increment operator ++ then by this cout<<i++ ; The snswer will be 1 however after this statement the value of i will be 2 And its opposite in case of ++i in it cout<<++i; The answer will be 2 because increment operator is used first and then i is written.
1st Jul 2020, 6:06 AM
Uzair
Uzair - avatar
+ 3
For Increment and decrement
1st Jul 2020, 6:16 PM
Jahongir Hayitov
Jahongir Hayitov - avatar
+ 3
for example int x=5; cout <<++x; //6 int x=5; cout <<x++; //5
1st Jul 2020, 6:18 PM
Jahongir Hayitov
Jahongir Hayitov - avatar
+ 2
$¢𝐎₹𝔭!𝐨𝓝 I understand what you mean but in your answers was not explained the difference to i=i+1 (i think time efficience)
30th Jun 2020, 8:36 AM
Alexander Thiem
Alexander Thiem - avatar
+ 2
This was not part of the question.
30th Jun 2020, 8:37 AM
Sandra Meyer
Sandra Meyer - avatar
+ 2
Mahmud Nabil I wrote this thing with time efficency without being sure it is right..... Does not matter anymore
30th Jun 2020, 5:43 PM
Alexander Thiem
Alexander Thiem - avatar
+ 2
Oh tnx uzair
1st Jul 2020, 6:07 AM
Umais Khan
Umais Khan - avatar
+ 2
Consider a=5,b=10 ++a means pre increment.... value of "a" increment first before any "opperation" carried out so a*b=6*10=60,then a=6 and b=10 a++ means post increment .....The value of "a" increment after opperation carried out. So a*b=5*10..then a vaue increment then a=6 ....same is a-- and --a ....but hear value is decrement
1st Jul 2020, 12:54 PM
Pratheesh S
Pratheesh S - avatar
+ 1
Alexander Thiem I just wanted to know the explanation because it's unintuitive to me. Sorry for whatever made you use '😬' emoji.
30th Jun 2020, 5:04 PM
Mahmud Nabil
Mahmud Nabil - avatar
+ 1
We use these for increment or decrement....Meanwhile Let's take a variable V=0. Now, If you want an increment of a number or variable..... Then, V=V++; What is simply does is it will increase V's value by one after the operation or u can say after the compilation of the program. Now if u want to decrement of a number or variable. Then, V=--V Now, what this does is first it will first decrease the value of V then print the value of it.....suppose V's value is 2 --V will decrease the value of V by 1 then the result will be V=1......! I hope u got my point...!☺
1st Jul 2020, 12:58 PM
Arya Deep Chowdhury
Arya Deep Chowdhury - avatar
+ 1
for example: int i=1; i++; // i=1 cout<<i; // 2 int j=1; ++j; // j=2 cout<<j; // 2
1st Jul 2020, 1:46 PM
Bakhtiyor
Bakhtiyor - avatar
0
I think that : cout<<i++; Takes the same time as cout<<i; or atleast less time than cout<<i; i=i+1; so it firtsly saves time and secondly shortens your code.
30th Jun 2020, 8:21 AM
Alexander Thiem
Alexander Thiem - avatar
0
Alexander Thiem If person know how the thing works then s/he definately know why and where to use.
30th Jun 2020, 8:32 AM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
0
This Is Things In Your Code For Loop Or Anything In for loops You things to break your loop. If You Dont make your loop is infinity loops
1st Jul 2020, 5:45 AM
Defense Hack
Defense Hack - avatar
0
Np 😊
1st Jul 2020, 6:20 AM
Uzair
Uzair - avatar