[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

C Programming :: Floating Point Problems - Discussion

Home > C Programming > Floating Point Problems > MCQs Questions Discussion

3 / 6

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

#include<stdio.h>
void main() {
int i,j,k;
j = 5;
i = 2 *j/2;
k = 2 *(j/2);
}

Ai = 5, k = 5

Bi=4,k=4

Ci = 5, k = 4

Di = 4, k = 5

Answer: Option (Login/Signup)

Show Explanation

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.


 


Asked In ::

Post Your Answer Here:     

Reply    
Rate This: +0 -0
    Report


Report Error

Please Login First Click Here