malloc basics
#include <stdio.h>
#include <stdlib.h>
int main() {
// Allocate memory for an integer
int ptr = (int)malloc(sizeof(int));
if (ptr == NULL) {
// Allocation failed
printf("Memory allocation failed\n");
return 1;
}
// Assign a value to the allocated memory
*ptr = 42;
// Print the value
printf("Value: %d\n", *ptr);
// Deallocate the memory
free(ptr);
return 0;
}