当前位置:网站首页>Malloc C language
Malloc C language
2022-07-29 03:40:00 【SHolmes1854】
page 101
the standard library provides analogous functions called malloc and free that have no such restrictions;
page 167
the functions malloc and calloc obtain blocks of memory dynamically.
void *malloc( size_t n)returns a pointer to n bytes of uninitialized storage, or NULL if the request can not be satisfied.
void *calloc( size_t n, size_t size)returns a pointer to enough space for an array of n objects of the specified size, or NULL if the request cannot be satisfied. The storage is intialized to zero.
The pointer returned by malloc or calloc has the proper alignment for the object in question, but it must be cast into the appropriate type, as in
int *ip;
ip = ( int * ) calloc ( n ,sizeof( int ) );
free (p) frees the space pointed to by p, where p was originally obtained by a call to malloc or calloc. There are no restrictions on the order in which space is freed, but it is a ghastly error to free something not obtained by
calling calloc or malloc.

It means c Standard library files stdlib.h It has malloc function
Its function definition is like this :
void *malloc( size_t size)
From this we can see , The return value of this function is null pointer type . This pointer points to the memory space allocated according to our needs , If the request fails ( That is, if the space allocation fails ) return NULL.
The following example says
str = ( char * ) malloc( 15 );Distribution 15byte Space , then malloc The function returns a pointer to this 15byte Spatial void*, Null pointer type . Then cast the type to char * type


Two pictures are from https://www.tutorialspoint.com/c_standard_library/c_function_malloc.htm
边栏推荐
- HDU多校第二场 1011 DOS Card
- RHCE的at,crontab的基本操作,chrony服务和对称加密和非对称加密
- Configure vscade to realize ROS writing
- 2. Variables and scope
- Getting started with caspin
- Violence recursion to dynamic programming 01 (robot movement)
- Rongyun IM & RTC capabilities on new sites
- 机器学习【Numpy】
- Excel拼接数据库语句
- RHCE's at, crontab's basic operations, the Chrony service, symmetric encryption and asymmetric encryption
猜你喜欢

Various minor problems of jupyter notebook, configuration environment, code completion, remote connection, etc

NXP i.mx8mp-deepviewrt

Android view system and custom view Series 1: (kotlin version)

Idea configuration web container and war packaging

for_each用法示例

How does DataGrid export and recover the entire database data, using a single SQL file

Process tracking of ribbon principle

Realize multi-level linkage through recursion

Why BGP server is used in sunflower remote control? Automatic optimal route and high-speed transmission across operators

Matlab learning -- structured programs and user-defined functions
随机推荐
Simple understanding of CDN, SDN and QoS
后缀自动机(sam)板子 from jly
再学EXKMP(EXKMP模板)
Web uploader cannot upload multiple files
Producer consumer model of concurrent model
Pp-yoloe details
力扣每日一题-第44天-205. 同构字符串
Use of leak scanning (vulnerability scanning) tool burpsuite or burp Suite (with installation and installation package download of burpsuite+1.7.26)
5年多工作经验,工资给15k,要是你,你会接受吗?
Shortcut key for adjusting terminal size in ROS
无法一次粘贴多张图片
如何判定是stun协议
3.2 model saving and loading
How does DataGrid export and recover the entire database data, using a single SQL file
(codeforce547)C-Mike and Foam(质因子+容斥原理)
代码 ~ 隐藏或禁用状态栏和虚拟按键
Sunflower senior product director technology sharing: "how to apply national remote control" in AD domain environment
How close can QA be to business code QA conducts testability transformation on business code
Practical application cases of digital Twins - smart energy
Division of data link layer, protocols used in data link layer and detailed introduction