[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:35:00 PM

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

osmium

7/3/2011 4:58:00 PM

0

"vinay kumar" wrote:

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

A leading zero indicates octal.


Vincenzo Mercuri

7/3/2011 5:06:00 PM

0

vinay kumar wrote:

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

#include <stdio.h>

int main(void) {
int d = 010;
printf("%o\n", (unsigned int) d);
return 0;
}

Check the differences.

Vincenzo Mercuri

7/3/2011 5:19:00 PM

0

Vincenzo Mercuri wrote:


> printf("%o\n", (unsigned int) d);

or rather,

printf("%0o\n", (unsigned int) d);

if you want to display it in octal form. Just

printf("%d\n", d);

if you want to convert and display it in decimal base.

Vincenzo Mercuri

7/3/2011 5:22:00 PM

0

Vincenzo Mercuri wrote:

> Vincenzo Mercuri wrote:
>
>
>> printf("%o\n", (unsigned int) d);
>
> or rather,
>
> printf("%0o\n", (unsigned int) d);

printf("0%o\n", (unsigned int) d);

Gosh, I cannot write it correctly today. I'll make it.
I better be friend to Knode.

Geoff

7/3/2011 7:32:00 PM

0

On Sun, 3 Jul 2011 09:34:33 -0700 (PDT), vinay kumar
<vinay5b9@gmail.com> wrote:

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

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

This sounds like an interview question or a homework problem.
What do you think the output is? Did you compile and run it?

Joe Pfeiffer

7/3/2011 8:08:00 PM

0

vinay kumar <vinay5b9@gmail.com> writes:

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

I don't want to be too rude, but you could compile and run it and find
the output for yourself much faster than you can expect an answer here.

H Vlems

7/4/2011 6:34:00 AM

0

On 3 jul, 22:08, Joe Pfeiffer <pfeif...@cs.nmsu.edu> wrote:
> vinay kumar <vinay...@gmail.com> writes:
> > main()
> > {
> > int d=010;
> > printf("%d",d);
> > }
>
> I don't want to be too rude, but you could compile and run it and find
> the output for yourself much faster than you can expect an answer here.

My guess is that the OP did do that. And it failed to compile because
printf
wasn't defined. If the OP had managed to find the answer to that in
his textbook then the
question would never have arrived here.
I seriously doubt the OP is interested in niceties as main() vs.
main(void) or int main(void).
Hans

Nick

7/4/2011 7:17:00 AM

0

Hans Vlems <hvlems@freenet.de> writes:

> On 3 jul, 22:08, Joe Pfeiffer <pfeif...@cs.nmsu.edu> wrote:
>> vinay kumar <vinay...@gmail.com> writes:
>> > main()
>> > {
>> > int d=010;
>> > printf("%d",d);
>> > }
>>
>> I don't want to be too rude, but you could compile and run it and find
>> the output for yourself much faster than you can expect an answer here.
>
> My guess is that the OP did do that. And it failed to compile because
> printf
> wasn't defined. If the OP had managed to find the answer to that in
> his textbook then the
> question would never have arrived here.
> I seriously doubt the OP is interested in niceties as main() vs.
> main(void) or int main(void).

My guess is he didn't. My guess is it's our resident troll again.
Let's count shall we:

no #includes
no type for main
no void
no trailing newline on printf
no return from main

5 out of 5.

That's ignoring the actual problem of course.
--
Online waterways route planner | http://ca...
Plan trips, see photos, check facilities | http://canalp...

Joe Pfeiffer

7/4/2011 1:25:00 PM

0

Hans Vlems <hvlems@freenet.de> writes:

> On 3 jul, 22:08, Joe Pfeiffer <pfeif...@cs.nmsu.edu> wrote:
>> vinay kumar <vinay...@gmail.com> writes:
>> > main()
>> > {
>> > int d=010;
>> > printf("%d",d);
>> > }
>>
>> I don't want to be too rude, but you could compile and run it and find
>> the output for yourself much faster than you can expect an answer here.
>
> My guess is that the OP did do that. And it failed to compile because
> printf
> wasn't defined. If the OP had managed to find the answer to that in
> his textbook then the
> question would never have arrived here.
> I seriously doubt the OP is interested in niceties as main() vs.
> main(void) or int main(void).
> Hans

Checking... at least under GCC, it compiles (with a warning due to
printf()), runs, and gives the expected result.

Willem

7/4/2011 3:12:00 PM

0

Hans Vlems wrote:
) On 3 jul, 22:08, Joe Pfeiffer <pfeif...@cs.nmsu.edu> wrote:
)> vinay kumar <vinay...@gmail.com> writes:
)> > main()
)> > {
)> > int d=010;
)> > printf("%d",d);
)> > }
)>
)> I don't want to be too rude, but you could compile and run it and find
)> the output for yourself much faster than you can expect an answer here.
)
) My guess is that the OP did do that. And it failed to compile because
) printf
) wasn't defined.
Why do you guess that? My guess is that it never even came near a compiler.

If the OP had managed to find the answer to that in
) his textbook then the
) question would never have arrived here.

True, but if the OP had actually opened his textbook he would have had a
much better chance at finding the answer.

) I seriously doubt the OP is interested in niceties as main() vs.
) main(void) or int main(void).

That is just a stick to hit people with when they post homework questions.

HTH HAND

SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT