Note 1

Take Note:

Take a note while surfing.

Note With Ink

Give your Note a Colorful Tag.

Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.

Think With Ink

Differ your Content by Color.

Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape

Note With Ink

Simple an Easy Way to take a note.

Easy to Access

Get the same in next visit.

Please wait...

C Programming :: Floating Point Problems

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.


Post Your Answer Here:     

Reply     |    Rate This: +0 -0      |     Report     |     To Reading List

Report Error

Please Login First Click Here