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?
- ++a++;
- a += 1;
- a ++ 1;
- a = a +1;
- a = +1;
Discussion:
20 comments Page 1 of 2.
Venkat said:
1 decade ago
a += 1 means a=a+1; //so it is correct
a = a+1; //it is also correct
a = a+1; //it is also correct
Jatinders said:
1 decade ago
This += is known as short hand operator which same as variable = variable +1; .
Anushiya said:
1 decade ago
a=a+1 is is correct we can also declare as a+=1
Gowrishangar said:
1 decade ago
In the option 4 a= +1 is correct or not & why?
Anandhajothi.s said:
1 decade ago
In the option 4 a=+ correct or not and why?
Vedhu said:
1 decade ago
a+=1 also mean by a=a+1, so both are same.
Neearj kumar said:
1 decade ago
This += is known as short hand operator which same as variable = variable +1; .
Tulasi Reddy said:
1 decade ago
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;
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:
1 decade ago
This += is known as short hand operator who same a=a+1 (a+=1 also mean by a=a+1)
Santosh said:
1 decade ago
This += is known as short hand operator which same as variable = variable +1; .
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers