[prog] Bug!!

Sachin sachinr at vsnl.in
Sun Mar 2 10:30:25 EST 2003


Dear friends,


Please compile the source code shown below.If you find anything
anomalous,please do report.


Sachin

Program:

#include<stdio.h>
#include<malloc.h>

int main( )
 {

                                   char *ptr;
                                    ptr=(char *)malloc(20);
                                    strcpy(ptr,"sachin");
                                    printf ("\nThe value of ptr:%s and its
address:%p\n",ptr,ptr);
                                    free(ptr);
                                    printf ("\nThe value of ptr:%s and its
address:%p\n",ptr,ptr);
                                    strcpy(ptr,"babu");
                                     printf ("\nThe value of ptr:%s and its
address:%p\n",ptr,ptr);
}

                                                             My program
,instead of printing segmentation fault  ,faithfully prints both the
strings.How it is possible?


Sachin



More information about the Programming mailing list