当前位置:网站首页>榕树贷款C语言结构体里的成员数组和指针
榕树贷款C语言结构体里的成员数组和指针
2022-07-27 01:51:00 【dongsijia】
榕树贷款执行下面的Test函数,分析会输出上面结果以及代码中存在什么问题。
1、笔试题1
void GetMemory(char* p)
{
p = (char*)malloc(100);
}
void Test(void)
{
char* str = NULL;
GetMemory(str);
strcpy(str, "hello world");
printf(str); //将str的首地址传给printf函数,可行
榕树贷款分析:
上面这段程序有三个问题:
第一:榕树贷款在Test函数中调用GetMemory函数时,传递的是str的值,所以GetMemory函数的参数p只是str的一份临时拷贝,与str没有任何关系,将动态开辟的100个字节交由指针p管理并不会对str产生任何影响;而且榕树贷款就算传递的是str的地址,malloc函数申请空间也有可能失败;
第二:榕树贷款由于GetMemory函数并没有能让str获得空间,所以str仍为NULL,这时调用strcpy函数会导致程序错误;
第三:榕树贷款代码中并没有对动态开辟的100个字节空间进行free,会导致内存泄漏;
边栏推荐
- Spark Learning Notes (VI) -- spark core core programming RDD action operator
- 安全员及环保员岗位职责
- MySQL underlying data structure
- “满五唯一”和“满二唯一”是什么?有什么不同?
- vector 转 svg 方法
- 正方形数组的数目(DAY 81)
- Docker creates MySQL 8.x container and supports Mac and arm architecture chips
- impala 执行计划详解
- Comprehensive care analysis lyriq Ruige battery safety design
- 架构基本概念和架构本质
猜你喜欢

Deep learning vocabulary embedded, beam search

Jmeter分布式压测

Add support for @data add-on in idea

Comprehensive care analysis lyriq Ruige battery safety design

网络安全/渗透测试工具AWVS14.9下载/使用教程/安装教程

深入理解Mysql索引底层数据结构与算法

A new paradigm of distributed deep learning programming: Global tensor

【树链剖分】2022杭电多校2 1001 Static Query on Tree

关于OpenFeign的源码分析

Portraiture5 new and upgraded leather filter plug-in artifact
随机推荐
深度学习——词汇embedded、Beam Search
Worthington果胶酶的特性及测定方案
优炫数据库集群如何唯一标识一条用户SQL
spark:地区广告点击量排行统计(小案例)
Code practice when the queue reaches the maximum length
国内服务器与海外服务器用1个数据库,怎样可以访问的快?
Volatile keyword and its function
opiodr aborting process unknown ospid (21745) as a result of ORA-609
Spark: ranking statistics of regional advertising hits (small case)
[flask] the server obtains the request header information of the client
[1206. Design skip table]
Worthington木瓜蛋白酶解离系统解决方案
最低票价(DAY 80)
【1206. 设计跳表】
Worthington过氧化物酶活性的6种测定方法
MySQL中文失败问题
Yilingsi T35 FPGA drives LVDS display screen
Code review pyramid
redis入门练习
How to design the red table of database to optimize the performance