linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* malloc question
@ 2011-04-26 10:33 Randi Botse
  2011-04-26 10:40 ` Daniel Baluta
  2011-04-26 15:05 ` Glynn Clements
  0 siblings, 2 replies; 6+ messages in thread
From: Randi Botse @ 2011-04-26 10:33 UTC (permalink / raw)
  To: linux-c-programming

Hi All,

I want to ask malloc() behaviour, consider these codes;

...
char *ptr = malloc(1);
strcpy(ptr, "what");
puts(ptr);
....

Confusingly, the strcpy() copied all bytes to ptr, but I just manage
to allocate ptr only for 1 byte, I guess I will have segfault here,
why this happen? why the string successfully copied into ptr? , is
those code legal?

Randi,

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-04-26 15:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-26 10:33 malloc question Randi Botse
2011-04-26 10:40 ` Daniel Baluta
2011-04-26 10:54   ` ratheesh kannoth
2011-04-26 10:57     ` Daniel Baluta
2011-04-26 11:50       ` ratheesh kannoth
2011-04-26 15:05 ` Glynn Clements

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