linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* What compiler is doing when we pass unnecessary parameters in scanf
@ 2009-07-29 14:18 RAM_LOCK
       [not found] ` <f662f0210907290855m57c191e2pb8ba28dc3d87f780@mail.gmail.com>
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: RAM_LOCK @ 2009-07-29 14:18 UTC (permalink / raw)
  To: linux-c-programming


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

Scenario : I
-------------
root@kaushik_Fedora11 ~/C/LET_US_C/ch-1> cat simple-interest.c
#include <stdio.h>

void main ()
{
        int p;
        float i=0;
        printf ("enter the principal amount\n");
        scanf ("%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 : 25.000000


Scenario : II
-------------
> cat simple-interest.c
#include <stdio.h>

void main ()
{
        int p;
        float i=0;
        printf ("enter the principal amount\n");
        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

-- 
View this message in context: http://www.nabble.com/What-compiler-is-doing-when-we-pass-unnecessary-parameters-in-scanf-tp24719839p24719839.html
Sent from the linux-c-programming mailing list archive at Nabble.com.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-10-09 12:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-29 14:18 What compiler is doing when we pass unnecessary parameters in scanf RAM_LOCK
     [not found] ` <f662f0210907290855m57c191e2pb8ba28dc3d87f780@mail.gmail.com>
2009-07-29 16:32   ` Fwd: " Aneesh Bhasin
2009-07-29 17:01 ` Glynn Clements
2009-10-09 12:45 ` shiva kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).