323,045 views
23 votes
23 votes
Determine the value of a and b at the end of the following code segment:

int a = 5;
int b = 10;
a++;
b*=a;
a = b + b;

The value stored for a is _____ and the value stored for b is _____

User Eric Chang
by
3.1k points

2 Answers

21 votes
21 votes

Answer:

a = 120 and b = 60

Step-by-step explanation:

a++ means a = a+1

b*=a is the same as b= a*b

After plugging in the variables,

Here are the results in order:

a = 6;

b = 60;

a = 120;

We only keep the nearest declared value of the variable, so "a" would equal 120 and "b" would equal 60.

User Clinton Roy
by
3.3k points
11 votes
11 votes

Answer:

15 and b is 20

Step-by-step explanation:

User Lucas Lopes
by
3.5k points