linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: shiva kumar <shiva@serc.iisc.ernet.in>
To: linux-c-programming@vger.kernel.org
Subject: Re: What compiler is doing when we pass unnecessary parameters in scanf
Date: Fri, 9 Oct 2009 05:45:04 -0700 (PDT)	[thread overview]
Message-ID: <25820534.post@talk.nabble.com> (raw)
In-Reply-To: <24719839.post@talk.nabble.com>


behavior of this is undefined just do man scanf

RAM_LOCK wrote:
> 
> 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-tp24719839p25820534.html
Sent from the linux-c-programming mailing list archive at Nabble.com.


  parent reply	other threads:[~2009-10-09 12:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]
  -- strict thread matches above, loose matches on Subject: below --
2009-07-29 16:02 Trevor Woollacott
2009-07-29 18:00 ` Sarkar, Kaushik
2009-07-29 14:18 RAM_LOCK

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=25820534.post@talk.nabble.com \
    --to=shiva@serc.iisc.ernet.in \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).