+ 5
How does ++i and i++ works?
I was doing a quiz and got confused with this question, i answered wrong, whats wrong int i=5; int j=i++; int k=j++; Console.Write(k+i) ; Please explain if u can
43 Respostas
+ 18
++a - increments and then uses the variable
a++ - uses and then increments the variable.
int x = 5;
int y = ++x; // y = 6
int x = 5;
int y = x++; // y = 5
+ 5
++i increments the value before the end of the statement whereas i++ does that after the execution of that statement ie. The value of i in i++ will remain same as i in that statement
+ 4
Int n1 = 1, n2 = 2;
Int n3, n4;
n3 = n1++;
// n3 = 1, n1 = 2
n4 = ++n2;
// n4 = 3, n2 = 3
// Same procedure for minus
//but with a decrement
+ 3
++i will change i's value when it goes to next line while i++ will change the value of i from the same line.
+ 2
If it was 12 i would not Even ask. The question is why it is 11 :D
+ 2
I guess so.
int i=5;
int j=i++;
int k=j++;
Console.Write(k+i);
So now my
i is 6, j is 6 and k is 5.
+ 2
Steps:
1. i=5.
2. j=5, i=6.
3. k=5, j=6.
4. Write (5+6) // answer: 11
+ 2
Yep now i got it thanks ;>
+ 2
x-= means x= x-x
so if x is 7 the answer is 14 because
x = 7 - (-7) = 7+7 = 14
+ 2
++i means add 1 before using it
i++ means add 1after its first use
+ 2
i++ means increment before using
But ++ i means after one use increment is applied
+ 2
X=6
X++
Then x=6
++X
Then X=7
+ 2
Here in that question i=5
J=i++ then j=5
K=j++
Then j=6
k+i=11
+ 2
++X means pre increment so we increased it by one so x=7 explain will you know it better
+ 2
If operator first so do it which +
second you can do what you want
Which may be assign or compare and vice versa
+ 2
Here simple logic to understand the concept,don't get confused.
ā¢Before implemention => ++a
ā¢After implementation=> a++
Lesson 1=>
If the increment is after the variable
(like a++) then the incrementing variable by one in next attempt of the statement
ā¢For example=>
int a; //undefined
a++;// a is not incremented by one
console.log(a);//a is incremented by one and logged out a=1;
ā¢One more Example=>
for(int a=0; a<=1;a++);//a is declare and initialized by 0 and condition satistified as true and a is not incremented by one instead a is increment next iteration of the for-loop sequence
In-brief =>
ā¢Iteration 1: a=0;a<=1;a=0;//instead of a=1
by a++
ā¢iteration 2: a=1;a<=1;a=1;//previously a=0 and a is incremented by one with the help of a++ by next attempt of the statement
ā¢iteration 3: a=2;a<=1;a++;//loop stops by condition false(2<=1) and value of a =2
Lesson 2=>
If the increment is before the variable
(like ++a) then the implementing variable by one is done at that point of execution of that statement
+ 1
do you understand what is prefix and Postfix variable entry? what is their difference?
+ 1
And how much in this:
x=7
x -= -x