This is exactly right. If it happens to work it's probaby because a pointer to the current top of heap was returned by malloc(), and just by luck writing to it did not mess anything up. For fun, try this:
main() { int *p=malloc(0); int *q = malloc(sizeof(int)); *p=2566; *q = 42; printf("%d\n",*p); getchar(); } On Jun 2, 1:16 pm, "Karthikeyan V.B" <kartmu...@gmail.com> wrote: > It does not return a valid address. > > The result of malloc(0) is implementation defined and therefore unreliable. > > Some compiler implementations will cause it to return a NULL pointer, > others may return some other value (but it still can't/shouldn't be used to > access memory). > > The memory cannot be used, (however it may require free()ing). -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.