I just started learning the programming language C and am having a problem while solving 1 exercise below.
Write a program that dynamically allocates 10 bytes of memory for a pointer, with the provided function template as follows: bool allocate10Bytes(uint8_t *outPtr);
- outPtr: output pointer
- return: true: If the allocation is successful. false: If the allocation failed.
I tried with the following code but the pointer in main function is still not allocated.
bool allocate10Bytes(uint8_t* outPtr)
{
outPtr = (uint8_t*)malloc(10 * sizeof(uint8_t));
if (outPtr == NULL) {
return false;
}
return true;
}
int main(void)
{
uint8_t* p = NULL;
bool success = allocate10Bytes(p);
if (success) free(p);
return 0;
}
Please help me. Thank you very much!