文档
注册
评分
提单
论坛
小智

malloc

内存分配。

void *malloc(size_t size);

参数

参数名

描述

取值范围

输入/输出

size

申请内存的字节数。

非负数

输入

返回值

  • 成功:返回指向分配内存的指针
  • 失败:返回空指针

示例

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "kqmalloc.h"

#define KQMALLOC_TEST_LEN 10

void MallocExample()
{
    int8_t *res = (int8_t *)malloc(KQMALLOC_TEST_LEN);
    if (res == NULL) {
        printf("res is null\n");
    } else {
        printf("malloc pointer address: %lx\n", res);
        free(res);
    }
}

int main(void) {
    MallocExample();
    return 0;
}

运行结果:

malloc pointer address: ffff97ae8174
搜索结果
找到“0”个结果

当前产品无相关内容

未找到相关内容,请尝试其他搜索词