HDU5536 Chip Factory 【01 dictionary tree】

2022-12-20   ES  

Reference link:
https://www.cnblogs.com/zhanjxcom/p/5766844.html
http://www.runoob.com/cprogramming/c-function-realloc.html

Application and release of dynamic memory must be paired. The number of malloc and free in the program must be the same, otherwise there must be errors (New/Delete)

The effect of

Malloc and New is similar, but if you want to add memory, you must use the Realloc function.

#include <iOSTREAM> 
 #include <cstdlib> 
 #include <cstring> 
 using namespace std; 


 int Main () 
 {{ 
     char *p; 
     p = (char *) malloc (10 *sizeof (char)); 
     COUT << "p:" << SIZEOF (P) << Endl; 
     // After using the Malloc function, generally use Memset to talk about memory initialization 
     memSet (P, 0,10*sizeof (char)); 

     strcpy (p, "COME on"); 
     COUT << "p:" << P << Endl; 

     p = (char *) Realloc (p, 20 *sizeof (char)); 
     COUT << "p:" << SIZEOF (P) << Endl; 

     strcat (p, ", baby!"); 
     COUT << "p:" << P << Endl; 

     free (p); 


     p = new char [10]; 
     strcpy (p, "COME on"); 
     COUT << "p:" << P << Endl; 
     p = (char *) Realloc (p, 20 *sizeof (char)); 
     COUT << "p:" << SIZEOF (P) << Endl; 

     strcat (p, ", baby!"); 

     COUT << "p:" << P << Endl; 
     delete [] p; 

     Return 0; 

 }

source

Related Posts

X64 VS2013 C ++ traversed all files under all files in the catalog using Findnext () to interrupt cdownload during debugging

pHP related knowledge to learn about it (1)

Center 7 deploy mysqlkevin

OpenPose Installation Configuration Fool Version Tutorial

HDU5536 Chip Factory 【01 dictionary tree】

Random Posts

ubuntu20.04 Virtual environment creation and use Ubuntu20.04 to create a virtual development environment

POJ3006, Dirichlet’s theorem on Arithmetic Progressions, Di Likrey theorem.

IOS-dynamic library and static library

STM32F030CT86 timer 3 channel 1 to verify the PWM front and rear cut mode

[244 Issue] The back slope \\ in mysql, too pit! Intersection