37 lines
965 B
C

#include "src.h"
#include "src.h"
#include <stdio.h>
#include <stdlib.h>
void c11() {
int num_elements;
printf("Enter number of elements (Malloc): ");
scanf("%d", &num_elements);
// Allocate the needed memory
int *elements = malloc(sizeof(int) * num_elements);
// Read the values in one by one into the memory
printf("Enter elements:\n");
int *end_addr = elements + num_elements; // Find end of memory region
while (elements < end_addr) {
scanf("%d", elements);
elements++;
}
elements--; // Slight offset to ensure correct alignment of the pointer
printf("\n"); // Insert newline to separator reads from output
// Reset the pointer to the start of the memory region
elements = elements - num_elements;
while (num_elements--) {
elements++;
printf("Memory Address of %d is %p\n", *elements, elements);
}
}
int main() {
print_header();
c11();
return 0;
}