Re: printf
- From: "Robert Gamble" <rgamble99@xxxxxxxxx>
- Date: 29 Jul 2005 06:45:23 -0700
Sensei wrote:
> On 2005-07-29 07:32:14 -0500, "biras" <rbiras@xxxxxxxxxxxxxx> said:
>
> > #include<stdio.h>
>
> Normal.
Maybe legal, but hopefully not "normal".
#include <stdio.h> is much preferred.
> > void main( )
>
> int main() as sombody said *very* correctly.
What's wrong with int main (void) ?
> > {
> > char *p;
> > p="yes";
>
>
> You are *really* lucky it didn't crash. You are writing into a random
> portion of memory.
First off, this is perfectly fine, would you also object to char *p =
"yes"? If not, what do you think the difference is between the two?
Secondly, I think you would be lucky if writing to a "random portion of
memory" *did* crash your program, there are far worse things that could
happen like not realizing that there is a problem (which there isn't in
this case).
> > printf(p);
>
>
> You still have to allocate p.
p has been allocated, what do you think the definition did? Do you
mean the space to which p points has not been allocated? If so, that
is also incorrect.
>
> > }
> >
> > output : yes
> > how printf is giving output ?
>
>
> By luck now. If you correct the errors, by calling your OS syscalls.
I think you need to crack open your C book before trying to correct
someone again ;)
Robert Gamble
.
- Follow-Ups:
- Re: printf
- From: Sensei
- Re: printf
- References:
- printf
- From: biras
- Re: printf
- From: Sensei
- printf
- Prev by Date: Re: is *ptr++ equivalent to *(ptr++)
- Next by Date: Re: validating problem
- Previous by thread: Re: printf
- Next by thread: Re: printf
- Index(es):
Relevant Pages
|