Chad
7/3/2011 11:13:00 PM
On Jul 3, 2:24 pm, Keith Thompson <ks...@mib.org> wrote:
> Chad <cdal...@gmail.com> writes:
> > On Jul 3, 10:47 am, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
> >> On 7/3/2011 12:32 PM, vinay kumar wrote:
>
> >> > main()
> >> > {
> >> > int d=010;
> >> > printf("%d",d);
> >> > }
>
> >> > please give with explanation
>
> >> Undefined, because a variable-argument function is used
> >> without a prototyped declaration.
>
> >> Also implementation-defined, because the final line of text
> >> output is not terminated with a newline.
>
> >> Also either (1) "semi-undefined" because a C90 int-valued
> >> function returns without returning a value, or (2) implementation-
> >> defined because a C99 compiler must diagnose a function definition
> >> without return type, and *if* it translates the program anyhow it
> >> gives it an implementation-defined meaning.
>
> >> ... but the answer you're probably looking for is "8", and
> >> the explanation will be found in the low-numbered pages of your
> >> C textbook -- you know, that unopened volume you've been carrying
> >> around. Open it (it won't bite you), and see what it has to say
> >> about "integer constants" or some similar term.
>
> > I know I shouldn't do this, but I'm going to take the bait on this
> > one. How do you figure the output is the "8".
>
> Did you try running the program? What output did you get?
>
> Eric already explained how to find the explanation: see what your C
> textbook (or on-line tutorial, or copy of the standard) says about
> integer constants.
>
I got the number "8" after I compiled and ran this code on my Linux
box here at home. I just wasn't clear on why the computer produced the
number "8" and not the number "10".
Chad