Main(){ int i, j, *p; i = 25; j = 100; p = &i; // Address of i is assigned to pointer p printf("%f", i/(*p) ); // i is divided by pointer p}

A) Compile error
B) 1.00000
C) Runtime error.
D) 0.00000
Explanation: Error because i/(*p) is 25/25 i.e 1 which is int & printed as a float, so abnormal program termination, runs if (float) i/(*p) -----> Type Casting.

Showing Answers 1 - 29 of 29 Answers

NAVNISH JAIN

  • Dec 15th, 2005
 

it is compiler dependent.

NAVNISH JAIN

  • Dec 15th, 2005
 

it is compiler dependent.

  Was this answer useful?  Yes

C_learner

  • Jan 18th, 2006
 

It will mostly give run time error and not compile time error....

Also use typecasting i.e. use       (float)i/(*p); and you will get 1.0000.. as the answer

  Was this answer useful?  Yes

sravanan

  • May 15th, 2006
 

compiler error.because division is not possible usinsg pointers.

  Was this answer useful?  Yes

shweta

  • May 16th, 2006
 

hi,

this gives runtime error.

i tried to run program in vc with .c extension file.

it  gives runtime error

  Was this answer useful?  Yes

yousf

  • Jun 7th, 2009
 

This is compiler dependent..

This will work on most popular compilers.. At least it will work on gcc!

  Was this answer useful?  Yes

abhimanipal

  • Jan 24th, 2010
 

In GCC this gives garbage value

The reason for this could be that when we write printf("%f", i/(*p) ); the printf statement expects a floating point value. However it is not sure what kind of value will result after the division. So it prints junk.

  Was this answer useful?  Yes

track92

  • Jun 15th, 2010
 

p is a pointer to the int variable i and *p prints the value stored in the address (of i) which it points. So answer will be 1 but data type is float so it will print 1.000000.

  Was this answer useful?  Yes

The %f conversion specifier expects its corresponding argument to be of type double, but the result of i/(*p) is type int (since both operands have type int); therefore, the behavior is undefined (per 7.19.6.1.9); any result is possible, from printing 1.00000 to printing garbage to runtime errors. 

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions