当前位置:网站首页>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");
}
边栏推荐
- 论文导读 | 关于将预训练语言模型作为知识库的分析与批评
- What is 9D movie like? (+ common sense of dimension space)
- Markdown基础语法
- 医院在线问诊源码 医院视频问诊源码 医院小程序源码
- 27: Chapter 3: develop Passport Service: 10: [registration / login] interface: after the registration / login is OK, save the user session information (uid, utoken) to redis and cookies; (one main poi
- reduce--遍历元素计算 具体的计算公式需要传入 结合BigDecimal
- 在纽约寻找童真——新泽西州乐高乐园探索中心的美好一天
- 学习八股文的知识点~~1
- [test development] takes you to know what software testing is
- juypter notebook 修改默认打开文件夹以及默认浏览器
猜你喜欢

线程应用实例

yolov3 训练自己的数据集之生成train.txt

MySQL advanced learning summary 7: MySQL data structure - Comparison of hash index, AVL tree, B tree and b+ tree

Imitation Jingdong magnifying glass effect (pink teacher version)

为什么要做企业固定资产管理系统,企业如何加强固定资产管理

高频面试题

Tutorial (5.0) 10 Troubleshooting * fortiedr * Fortinet network security expert NSE 5

What is 9D movie like? (+ common sense of dimension space)

论文导读 | 关于将预训练语言模型作为知识库的分析与批评

论文导读 | 机器学习在数据库基数估计中的应用
随机推荐
ORA-01455: converting column overflows integer datatype
Hospital online inquiry source code hospital video inquiry source code hospital applet source code
R语言dplyr包na_if函数把向量数值中的控制转化为缺失值NA、按照映射规则把指定内容转化为缺失值NA
Markdown基础语法
LightGroupButton* sender = static_ cast<LightGroupButton*>(QObject::sender());
[test development] takes you to know what software testing is
2022.7.1-----leetcode.241
STM32G0 USB DFU 升级校验出错-2
ORA-01455: converting column overflows integer datatype
R language ggplot2 visualization: visualize the line chart and add customized X-axis label information to the line chart using labs function
在纽约寻找童真——新泽西州乐高乐园探索中心的美好一天
Preprocessing and preprocessing macros
【测试开发】一文带你了解什么是软件测试
性能测试如何创造业务价值
Compile oglpg-9th-edition source code with clion
In pytorch function__ call__ And forward functions
Golang concurrent programming goroutine, channel, sync
Obligatoire pour les débutants, cliquez sur deux boutons pour passer à un contenu différent
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
2022软件工程期末考试 回忆版