当前位置:网站首页>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");
}
边栏推荐
- Troubleshooting: kubectl reports an error validationerror: unknown field \u00a0
- [论文阅读] CA-Net: Leveraging Contextual Features for Lung Cancer Prediction
- [daily question] the next day
- MySQL advanced learning summary 7: MySQL data structure - Comparison of hash index, AVL tree, B tree and b+ tree
- 性能测试如何创造业务价值
- According to the atlas of data security products and services issued by the China Academy of information technology, meichuang technology has achieved full coverage of four major sectors
- ORA-01455: converting column overflows integer datatype
- [100 cases of JVM tuning practice] 02 - five cases of virtual machine stack and local method stack tuning
- 二进制操作
- Transformation of thinking consciousness is the key to the success or failure of digital transformation of construction enterprises
猜你喜欢
思维意识转变是施工企业数字化转型成败的关键
Introduction to the paper | application of machine learning in database cardinality estimation
In pytorch function__ call__ And forward functions
[100 cases of JVM tuning practice] 01 - introduction of JVM and program counter
High frequency interview questions
开发固定资产管理系统,开发固定资产管理系统用什么语音
M2dgr: slam data set of multi-source and multi scene ground robot (ICRA 2022)
Hongmeng's fourth learning
Novice must see, click two buttons to switch to different content
Introduction to the paper | analysis and criticism of using the pre training language model as a knowledge base
随机推荐
拦截器与过滤器的区别
Codeworks 5 questions per day (1700 average) - day 4
Mysql高级篇学习总结7:Mysql数据结构-Hash索引、AVL树、B树、B+树的对比
论文导读 | 关于将预训练语言模型作为知识库的分析与批评
Obligatoire pour les débutants, cliquez sur deux boutons pour passer à un contenu différent
Exness in-depth good article: dynamic series - Case Analysis of gold liquidity (V)
High frequency interview questions
ICDE 2023|TKDE Poster Session(CFP)
Excel查找一列中的相同值,删除该行或替换为空值
C file input operation
Installation of thingsboard, an open source IOT platform
Markdown basic grammar
How to delete the border of links in IE? [repeat] - how to remove borders around links in IE? [duplicate]
ICDE 2023|TKDE Poster Session(CFP)
How to clean up discarded PVs and their corresponding folders
Hongmeng's fourth learning
教程篇(5.0) 09. RESTful API * FortiEDR * Fortinet 网络安全专家 NSE 5
R language dplyr package Na_ The if function converts the control in the vector value into the missing value Na, and converts the specified content into the missing value Na according to the mapping r
STM32G0 USB DFU 升级校验出错-2
When converting from list to map, if a certain attribute may cause key duplication and exceptions, you can set the way to deal with this duplication