当前位置:网站首页>C的内存管理
C的内存管理
2022-07-02 17:50:00 【悠然少年心】
#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));//在堆栈分配一个空间
FTest*pName=calloc(10, sizeof(FTest));//分配十个内存并且全部为0
printf("%d \n\r", pName[4].x);
pName=realloc(pName,10+2*sizeof(FTest));//重新分配在后面添加两个FTest大小的内存
pName[12].x = 10;
printf("%d \n\r", 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 \r\n", str);
//中文字符一个汉字占两个字节所以拷贝3个只能拷贝到第二个的一半
char dest[20] = "秋水连天";
char dest1[20] = {
0};
memcpy(dest1, dest,3);//秋?
printf("%s \r\n", dest1);
system("pause");
}
边栏推荐
- How to delete the border of links in IE? [repeat] - how to remove borders around links in IE? [duplicate]
- 【每日一题】第一天
- How to use PS to extract image color and analyze color matching
- ORA-01455: converting column overflows integer datatype
- Redis (7) -- database and expiration key
- Excel查找一列中的相同值,删除该行或替换为空值
- 文字编辑器 希望有错误的句子用红色标红,文字编辑器用了markdown
- How to enable the run dashboard function of idea
- Troubleshooting: kubectl reports an error validationerror: unknown field \u00a0
- Stretchdibits function
猜你喜欢
Thoroughly understand the point cloud processing tutorial based on open3d!
MySQL advanced learning summary 8: overview of InnoDB data storage structure page, internal structure of page, row format
[论文阅读] CA-Net: Leveraging Contextual Features for Lung Cancer Prediction
新加坡暑假旅游攻略:一天玩转新加坡圣淘沙岛
LightGroupButton* sender = static_cast<LightGroupButton*>(QObject::sender());
The text editor hopes to mark the wrong sentences in red, and the text editor uses markdown
聊聊电商系统中红包活动设计
【JVM调优实战100例】02——虚拟机栈与本地方法栈调优五例
How can retail enterprises open the second growth curve under the full link digital transformation
Kubernetes three open interfaces first sight
随机推荐
AI开发调试系列第二弹:多机分布式调测探索之旅
拦截器与过滤器的区别
SQL training 2
R语言使用epiDisplay包的lrtest函数对多个glm模型(logisti回归)执行似然比检验(Likelihood ratio test)对比两个模型的性能是否有差异、广义线性模型的似然比检
@Component cannot get Dao layer
Three ways of function parameter transfer in C language
Golang并发编程——goroutine、channel、sync
Hospital online inquiry source code hospital video inquiry source code hospital applet source code
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
[test development] takes you to know what software testing is
How to play when you travel to Bangkok for the first time? Please keep this money saving strategy
R语言使用epiDisplay包的lsNoFunction函数列出当前空间中的所有对象、除了用户自定义的函数对象
R language uses Cox of epidisplay package Display function obtains the summary statistical information of Cox regression model (risk rate HR, adjusted risk rate and its confidence interval, P value of
Introduction to the paper | application of machine learning in database cardinality estimation
R language uses the lsnofunction function function of epidisplay package to list all objects in the current space, except user-defined function objects
Stm32g0 USB DFU upgrade verification error -2
Page title component
M2dgr: slam data set of multi-source and multi scene ground robot (ICRA 2022)
彻底搞懂基于Open3D的点云处理教程!
Hongmeng's fourth learning