Skip to main content
deleted 44 characters in body
Source Link
user142162
user142162

Consider your Test1 performs the following behavior:

 char * x1 = NULL; Test1 (x1); char * x1 = NULL; Test1 (x1); 

Test1 is done within the following:

 void test1 (char * t) / / t -> x1 -> null { t = (char *) malloc (11); // t now points a different place (the memory allocated), and the reference of x1 continues pointing to null strcpy (t, "1234567890"); // t value is "1234567890" but x1 continues pointing to null // Error, the memory that is pointed by t is never released } void test1 (char * t) / / t -> x1 -> null { t = (char *) malloc (11); // t now points a different place (the memory allocated), and the reference of x1 continues pointing to null strcpy (t, "1234567890"); // t value is "1234567890" but x1 continues pointing to null // Error, the memory that is pointed by t is never released } 
  
 printf ("\nTest1:%s \n", t1); / / Print the value of x1 (null) and the reference of t is lost printf ("\nTest1:%s \n", t1); / / Print the value of x1 (null) and the reference of t is lost 

Greetings

Note.- Excuse my bad English :P

Consider your Test1 performs the following behavior:

 char * x1 = NULL; Test1 (x1); 

Test1 is done within the following

 void test1 (char * t) / / t -> x1 -> null { t = (char *) malloc (11); // t now points a different place (the memory allocated), and the reference of x1 continues pointing to null strcpy (t, "1234567890"); // t value is "1234567890" but x1 continues pointing to null // Error, the memory that is pointed by t is never released } 
 
 printf ("\nTest1:%s \n", t1); / / Print the value of x1 (null) and the reference of t is lost 

Greetings

Note.- Excuse my bad English :P

Consider your Test1 performs the following behavior:

char * x1 = NULL; Test1 (x1); 

Test1 is done within the following:

void test1 (char * t) / / t -> x1 -> null { t = (char *) malloc (11); // t now points a different place (the memory allocated), and the reference of x1 continues pointing to null strcpy (t, "1234567890"); // t value is "1234567890" but x1 continues pointing to null // Error, the memory that is pointed by t is never released } 
 
printf ("\nTest1:%s \n", t1); / / Print the value of x1 (null) and the reference of t is lost 
Source Link
xlarsx
  • 991
  • 1
  • 9
  • 8

Consider your Test1 performs the following behavior:

 char * x1 = NULL; Test1 (x1); 

Test1 is done within the following

 void test1 (char * t) / / t -> x1 -> null { t = (char *) malloc (11); // t now points a different place (the memory allocated), and the reference of x1 continues pointing to null strcpy (t, "1234567890"); // t value is "1234567890" but x1 continues pointing to null // Error, the memory that is pointed by t is never released } 
 printf ("\nTest1:%s \n", t1); / / Print the value of x1 (null) and the reference of t is lost 

Greetings

Note.- Excuse my bad English :P