C# Programming - Operators - Discussion

Discussion Forum : Operators - General Questions (Q.No. 1)
1.
Which of the following are the correct ways to increment the value of variable a by 1?
  1. ++a++;
  2. a += 1;
  3. a ++ 1;
  4. a = a +1;
  5. a = +1;
1, 3
2, 4
3, 5
4, 5
None of these
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
20 comments Page 1 of 2.

Suman Mitra said:   5 years ago
main()
{
int a=0;
int x;
x=a++ + ++a * ++a + ++a - a++;
printf(" %d ", x);
return 0;
}
OUTPUT:

X=a++(0) + ++a(2) * ++a(3) + ++a(4) - a++(4)
=0+2*3+4-4
=6+4-4.
=10-4.
=6.

Deepak verma said:   9 years ago
This += is known as shorthand operator which same as variable = variable +1.
(1)

Vinay kumar pusuluri said:   9 years ago
First of all, a = 0 then post increment, then pre-increment 0 + 2 = 2 then it is multiplied with pre-increment then a value becomes 3 then 2 * 3 = 6 then a = 4 then 6 + 4 = 10 then 10 - 4 = 6.

Finally, ((0 + 2) * 3) + 4 - 4.

Rose said:   1 decade ago
++a is true. What about ++a+1?
a = a++1.

Srinivas said:   1 decade ago
Can any body tell me please what multithreading?

Srinivas said:   1 decade ago
What is difference between a++1 and a = +1?
(1)

Deepak Tiwari said:   1 decade ago
1. ++a++ this is wrong because only one same operator can use.

3. a++1 this is also wrong because one same operator not can use.

5. a=+1 its also wrong because operator used but not in correct way.

Sujeet said:   1 decade ago
B. a+=1; //means a=a+1; where a is an variable, if a is an integer type variable having value 10 then output will be 11.

a=a+1; //means if a is an integer type variable having value 10 then output will be 11;

So, both are increment by 1;

Krishna said:   1 decade ago
It was repeating and returning the zero.

Deepak said:   1 decade ago
main()
{
int a=0;
int x;
x=a++ + ++a * ++a + ++a - a++;
printf(" %d ", x);
return 0;
}

Ans :6. Anyone tell me how is done?


Post your comments here:

Your comments will be displayed after verification.