108k views
4 votes
Consider the following code segment.

int num = 5;
num *= 2;
num %= 6;
What is the value of num after the code segment is executed?
a. 1
b. 2
c. 4
d. 6
e. 10

User Existent
by
7.8k points

1 Answer

2 votes

Answer:

C. 4

Step-by-step explanation:

First we are given that num=5 ...(1)

-num value is 5

num =num*2 which is [5*2] = 10 ... (2)

-num value is now (10)

num =num-6 which is [10-6] =4 ... (3)

So the final answer is 4

User MarAja
by
6.7k points