malloc
Function Usage
Allocates memory.
Function Syntax
void *malloc(size_t size);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
size |
Number of bytes of the requested memory. |
The value cannot be negative. |
Input |
Return Value
- Success: A pointer to the allocated memory is returned.
- Failure: A null pointer is returned.
Example
#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;
}
Output:
malloc pointer address: ffff97ae8174
Parent topic: Function Syntax