C# Programming - Operators - Discussion

Discussion :: 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;

[A]. 1, 3
[B]. 2, 4
[C]. 3, 5
[D]. 4, 5
[E]. None of these

Answer: Option B

Explanation:

No answer description available for this question.

Venkat said: (May 9, 2011)  
a += 1 means a=a+1; //so it is correct
a = a+1; //it is also correct

Jatinders said: (Jul 8, 2011)  
This += is known as short hand operator which same as variable = variable +1; .

Anushiya said: (Jul 20, 2011)  
a=a+1 is is correct we can also declare as a+=1

Gowrishangar said: (Dec 2, 2011)  
In the option 4 a= +1 is correct or not & why?

Anandhajothi.S said: (Jan 10, 2012)  
In the option 4 a=+ correct or not and why?

Vedhu said: (Mar 1, 2012)  
a+=1 also mean by a=a+1, so both are same.

Neearj Kumar said: (Apr 13, 2012)  
This += is known as short hand operator which same as variable = variable +1; .

Tulasi Reddy said: (Jun 17, 2012)  
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 incrementing by 1;

Vipin Rathore Bimt said: (Dec 22, 2012)  
This += is known as short hand operator who same a=a+1 (a+=1 also mean by a=a+1)

Santosh said: (Jan 3, 2013)  
This += is known as short hand operator which same as variable = variable +1; .

Deepak said: (Feb 2, 2013)  
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?

Krishna said: (Sep 11, 2013)  
It was repeating and returning the zero.

Sujeet said: (Sep 18, 2013)  
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;

Deepak Tiwari said: (Feb 18, 2014)  
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.

Srinivas said: (Dec 9, 2014)  
What is difference between a++1 and a = +1?

Srinivas said: (Dec 9, 2014)  
Can any body tell me please what multithreading?

Rose said: (Mar 26, 2015)  
++a is true. What about ++a+1?
a = a++1.

Vinay Kumar Pusuluri said: (Sep 11, 2016)  
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.

Deepak Verma said: (Feb 4, 2017)  
This += is known as shorthand operator which same as variable = variable +1.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.