Consider the following program fragment, and choose the correct one.
void main()
{
int a, b = 2, c;
a = 2 * (b++);
c = 2 * (++b);
}
void main()
{
int a, b = 2, c;
a = 2 * (b++);
c = 2 * (++b);
}
A. a = 4, c = 8
B. a = 3, c = 8
C. b = 3, c = 6
D. a = 4, c = 6
E. b = 4, c = 6
Answer: Option A
Join The Discussion
Comments ( 3 )
Related Questions on Operators and Expressions
What does the ++ operator do in C when applied to a variable?
A. Decrements by 1
B. Adds 1
C. Doubles the value
D. Leaves it unchanged
Frist b++ is 2 now Frist ans is 2*2=4
NOW it's a increment operator then Frist b++ and ++b it's two times increment that's way b=4
B++ is Frist assign the value again increment this is postinremnt that's way after ans this is 3 and ++b is b=b+1 this is 4
Plz explain this pro
b++ = 3 in 1st condition
++b =4 due to 1st condition