added huge pages tests
This commit is contained in:
40
allocator/testallocator/simple_c.c
Normal file
40
allocator/testallocator/simple_c.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main() {
|
||||
int *ptr;
|
||||
int n, i;
|
||||
|
||||
printf("Enter the number of elements: ");
|
||||
scanf("%d", &n);
|
||||
// Allocate memory for n integers
|
||||
ptr = (int *)malloc(n * sizeof(int));
|
||||
|
||||
// Check if memory has been successfully allocated
|
||||
if (ptr == NULL) {
|
||||
printf("Memory not allocated.\n");
|
||||
return 1; // Exit the program
|
||||
}
|
||||
|
||||
// Memory has been successfully allocated
|
||||
printf("Memory successfully allocated using malloc.\n");
|
||||
|
||||
// Get the elements
|
||||
for (i = 0; i < n; i++) {
|
||||
printf("Enter element %d: ", i + 1);
|
||||
scanf("%d", &ptr[i]);
|
||||
}
|
||||
|
||||
// Print the elements
|
||||
printf("The elements are: ");
|
||||
for (i = 0; i < n; i++) {
|
||||
printf("%d ", ptr[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
// Free the allocated memory
|
||||
free(ptr);
|
||||
printf("Memory successfully freed.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user