[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

what is the output

vinay kumar

7/3/2011 4:32:00 PM

main()
{
int d=010;
printf("%d",d);
}

please give with explanation
34 Answers

Joachim Schmitz

7/3/2011 5:43:00 PM

0

vinay kumar wrote:
> main()
> {
> int d=010;
> printf("%d",d);
> }
>
> please give with explanation

What output do you get.
What output did you expect and why?

Eric Sosman

7/3/2011 5:48:00 PM

0

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.

--
Eric Sosman
esosman@ieee-dot-org.invalid

Keith Thompson

7/3/2011 7:15:00 PM

0

Eric Sosman <esosman@ieee-dot-org.invalid> writes:
> 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.

Actually, I think that the behavior of a program that violates a
constraint (given that the compiler chooses to translate it anyway)
is undefined, not implementation-defined.

[...]

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.ne...
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

ram

7/3/2011 7:29:00 PM

0

vinay kumar <vinay5b9@gmail.com> writes:
>main()
>{
>int d=010;
>printf("%d",d);
>}

Implicit function declarations have been removed from C,
so the function »printf« cannot be called there.

Joe Pfeiffer

7/3/2011 8:06:00 PM

0

vinay kumar <vinay5b9@gmail.com> writes:

> main()
> {
> int d=010;
> printf("%d",d);
> }
>
> please give with explanation

Please give with question?

Chad

7/3/2011 8:56:00 PM

0

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".

Chad

osmium

7/3/2011 9:21:00 PM

0

"Chad" wrote:

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".

1x8^1 + 0x8^0 = 8


Keith Thompson

7/3/2011 9:25:00 PM

0

Chad <cdalten@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.

If you're not interested in doing that, I can explain exactly
why the output is what it is, but you'd learn more by doing your
own research.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.ne...
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Chad

7/3/2011 11:13:00 PM

0

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

Morris Keesan

7/4/2011 1:10:00 AM

0

On Sun, 03 Jul 2011 19:13:06 -0400, Chad <cdalten@gmail.com> wrote:

> 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);
>> >> > }
....
> 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".

010 != 10

As someone else suggested, go read what any C reference has to say
about integer constants. Or just google for "C integer constant", and
see what the first result tells you.


--
Morris Keesan -- mkeesan@post.harvard.edu