当前位置:网站首页>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
边栏推荐
- Set functions in kotlin
- Learn exkmp again (exkmp template)
- Regular expression bypasses WAF
- 向日葵远程控制为何采用BGP服务器?自动最优路线、跨运营商高速传输
- How to judge stun protocol
- In depth C language (4) -- definition and use of switch
- Arm architecture and neural network
- @Configuration (proxybeanmethods = false) what's the use of setting this to false
- Android view system and custom view Series 1: (kotlin version)
- RTP 发送 和接收 h265
猜你喜欢
![Leetcode 1331 array sequence number conversion [map] the leetcode path of heroding](/img/be/d429d0c437dc5ed7cb4448e223a83a.png)
Leetcode 1331 array sequence number conversion [map] the leetcode path of heroding

Getting started with caspin

What have I learned from 200 machine learning tools?
![MOS管 —— 快速复苏应用笔记(贰)[参数与应用]](/img/54/eb040a51304192def8cfb360c7c213.png)
MOS管 —— 快速复苏应用笔记(贰)[参数与应用]

AI platform, AI midrange architecture

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

最新二开版漫画小说听书三合一完整源码/整合免签接口/搭建教程/带采集接口

(2022杭电多校三)1002-Boss Rush(状压DP+二分)

I.MX6U-驱动开发-2-LED驱动

Use of leak scanning (vulnerability scanning) tool burpsuite or burp Suite (with installation and installation package download of burpsuite+1.7.26)
随机推荐
(2022 Hangdian multi school III) 1002 boss rush (pressure dp+ dichotomy)
Simple code implementation of decision tree
Leetcode 1331 array sequence number conversion [map] the leetcode path of heroding
Introduction to static routing and dynamic routing protocols OSPF and rip and static routing configuration commands
Idea configuration web container and war packaging
Excel splicing database statement
C obtains JSON format data asynchronously from the web address
安装抓包证书
Tonight at 7:30 | is the AI world in the eyes of Lianjie, Jiangmen, Baidu and country garden venture capital continue to be advanced or return to the essence of business
向日葵资深产品总监技术分享:“国民远控”如何在AD域环境下应用
I.MX6U-驱动开发-2-LED驱动
NXP i.mx8mp-deepviewrt
Casbin入门
Install the packet capturing certificate
Understanding of p-type problems, NP problems, NPC problems, and NP hard problems in natural computing
CUDA GDB prompt: /tmp/tmpxft**** cudafe1.stub. c: No such file or directory.
Simple use of eventbus
Android view system and custom view Series 1: (kotlin version)
"Strangers once met" Summer Street Shen Shuyan_ Xia Mo Shen Shuyan's latest chapter
(2022杭电多校三)1011-Link is as bear(思维+线性基)