#include#include #include typedef struct { int x; int y; }FTest; int main() { #if 0 char p[128]; strcpy(p,"tom"); printf("%s n",p); char* ptr = malloc(128*sizeof(char));//在堆栈分配一个空间 FTest*pName=calloc(10, sizeof(FTest));//分配十个内存并且全部为0 printf("%d nr", pName[4].x); pName=realloc(pName,10+2*sizeof(FTest));//重新分配在后面添加两个FTest大小的内存 pName[12].x = 10; printf("%d nr", pName[12].x); if (ptr == NULL) { fprintf(strerror,"内存不够"); exit(EXIT_FAILURE); } else { strcpy(ptr,p); } free(ptr); #endif // 0 //memset 和memcpy char str[] = "IIII"; memset(str,'k', strlen(str));//参数:设置的数组,替换字符,替换前面几位 printf("%s rn", str); //中文字符一个汉字占两个字节所以拷贝3个只能拷贝到第二个的一半 char dest[20] = "秋水连天"; char dest1[20] = {0}; memcpy(dest1, dest,3);//秋? printf("%s rn", dest1); system("pause"); }



