# C Programming :: Floating Point Problems

**Home**>

**C Programming**>

**Floating Point Problems**>

**Discussion**

## 3. What would be the value of i and k in below C program?

void main() {

int i,j,k;

j = 5;

i = 2 *j/2;

k = 2 *(j/2);

}

**Answer:**

**Option C**

**Explanation :**

at first, glance looks like i value will be 4 and k value will be 4 too.

but if you see in second statement () has been used. why?

###### in first statement i = 2 *j/2; three operators have been used i.e = , * , / .

operator = has priority 14 and both operator * & / have priority as 3.

###### however operator * has high precedence than / so in above statement first multiplication will take place and then division will happen so that i will carry 5.

###### Now, in second statement () has been used for j/2. operator () (function call operator has priority 1 and highest precedence in c operator.) so the first j/2 operation will take place and then 2 * result of j/2 (i.e 2). so, k will carry 4.

###### An answer will be i = 5 and k = 4.

STEP-BY-STEP

at first, glance looks like i value will be 4 and k value will be 4 too.

but if you see in second statement () has been used. why?

###### in first statement i = 2 *j/2; three operators have been used i.e = , * , / .

operator = has priority 14 and both operator * & / have priority as 3.

###### however operator * has high precedence than / so in above statement first multiplication will take place and then division will happen so that i will carry 5.

###### Now, in second statement () has been used for j/2. operator () (function call operator has priority 1 and highest precedence in c operator.) so the first j/2 operation will take place and then 2 * result of j/2 (i.e 2). so, k will carry 4.

###### An answer will be i = 5 and k = 4.

Report Error

Please Login First Click Here