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 2 of 2.
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?
{
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:
1 decade ago
It was repeating and returning the zero.
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;
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:
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.
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:
1 decade ago
What is difference between a++1 and a = +1?
(1)
Srinivas said:
1 decade ago
Can any body tell me please what multithreading?
Rose said:
1 decade ago
++a is true. What about ++a+1?
a = a++1.
a = a++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.
Finally, ((0 + 2) * 3) + 4 - 4.
Deepak verma said:
9 years ago
This += is known as shorthand operator which same as variable = variable +1.
(1)
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.
{
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers