c - Random Behaviour with the format specifier -


i encountered strange behaviour following code:

int main() {     float a=7.9999999;     int b=5;     printf("%d %f",a,b); } 

now expected o/p of form of 7 , 5.00000 giving me random values? know kind of stuff should avoided learning perspective? why getting random value above snippet?

you're passing objects of types not correspond format specifiers. undefined behaviour (ub). 1 manifestation of ub print seemingly random garbage standard output. cannot expect particular outcome program ub.

your expectation misplaced.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -