当前位置:网站首页>Memory management of C
Memory management of C
2022-07-02 19:11:00 【Leisurely young heart】
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
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));// Allocate a space on the stack
FTest*pName=calloc(10, sizeof(FTest));// Allocate ten memories and all for 0
printf("%d \n\r", pName[4].x);
pName=realloc(pName,10+2*sizeof(FTest));// Reassign add two after FTest Size of memory
pName[12].x = 10;
printf("%d \n\r", pName[12].x);
if (ptr == NULL)
{
fprintf(strerror," Out of memory ");
exit(EXIT_FAILURE);
}
else
{
strcpy(ptr,p);
}
free(ptr);
#endif // 0
//memset and memcpy
char str[] = "IIII";
memset(str,'k', strlen(str));// Parameters : Array of settings , Replace character , Replace the first few
printf("%s \r\n", str);
// Chinese characters one Chinese character takes up two bytes, so copy 3 One can only be copied to half of the second
char dest[20] = " Autumn water stretches to the sky ";
char dest1[20] = {
0};
memcpy(dest1, dest,3);// autumn ?
printf("%s \r\n", dest1);
system("pause");
}
边栏推荐
- 高级性能测试系列《24. 通过jdbc执行sql脚本》
- 云呐|为什么要用固定资产管理系统,怎么启用固定资产管理系统
- How to delete the border of links in IE? [repeat] - how to remove borders around links in IE? [duplicate]
- [fluent] dart data type (VaR data type | object data type)
- Crypto usage in nodejs
- Learning summary of MySQL advanced 6: concept and understanding of index, detailed explanation of b+ tree generation process, comparison between MyISAM and InnoDB
- 学习八股文的知识点~~1
- 【JVM调优实战100例】02——虚拟机栈与本地方法栈调优五例
- Use cheat engine to modify money, life and stars in Kingdom rush
- ICDE 2023|TKDE Poster Session(CFP)
猜你喜欢
Use cheat engine to modify money, life and stars in Kingdom rush
Excel查找一列中的相同值,删除该行或替换为空值
UML class diagram
中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖
Troubleshooting: kubectl reports an error validationerror: unknown field \u00a0
M2dgr: slam data set of multi-source and multi scene ground robot (ICRA 2022)
[论文阅读] CA-Net: Leveraging Contextual Features for Lung Cancer Prediction
消息队列消息丢失和消息重复发送的处理策略
Novice must see, click two buttons to switch to different content
Transformation of thinking consciousness is the key to the success or failure of digital transformation of construction enterprises
随机推荐
Looking for innocence in New York -- a beautiful day at the discovery center of Legoland, New Jersey
Installation of thingsboard, an open source IOT platform
[100 cases of JVM tuning practice] 03 -- four cases of JVM heap tuning
【JVM调优实战100例】03——JVM堆调优四例
迷你高尔夫球场:伦敦休闲旅游好去处
Tips for material UV masking
R语言dplyr包filter函数筛选dataframe数据、如果需要筛选的数据列(变量)名称中包含引号则需要使用!!sym语法处理、否则因为无法处理引号筛选不到任何数据
新加坡暑假旅游攻略:一天玩转新加坡圣淘沙岛
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
How can retail enterprises open the second growth curve under the full link digital transformation
Excel如何进行隔行复制粘贴
为什么要做企业固定资产管理系统,企业如何加强固定资产管理
全志A33使用主线U-Boot
日期工具类(不定时更新)
Stm32g0 USB DFU upgrade verification error -2
Troubleshooting: kubectl reports an error validationerror: unknown field \u00a0
QT中的QPropertyAnimation使用和toast案列
PHP非对称加密方法私钥及公钥加密解密的方法
Excel finds the same value in a column, deletes the row or replaces it with a blank value
Excel查找一列中的相同值,删除该行或替换为空值