Re: What compiler is doing when we pass unnecessary parameters in scanf

Glynn Clements <[email protected]>
Newsgroups org.kernel.vger.linux-c-programming
Message-ID <[email protected]>
RAM_LOCK wrote:

> In the second scenario what value is it printing when i have given extra
> parameter in scanf?
> Does it vary from compiler to compiler?

>         scanf ("p:%d",&p);
>         i = (p*5*5)/100;
>         printf ("Interterest is : %f\n",i);
> }
> root@kaushik_Fedora11 ~/C/LET_US_C/ch-1> ./a.out
> enter the principal amount
> 100
> Interterest is : -9321198.000000

The p: isn't matched in the input, so scanf() skips the following %d
conversion, leaving p unchanged. So p will contain garbage (i.e. 
whatever value happened to be stored in that memory location already).

-- 
Glynn Clements <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.