36 lines
947 B
C
36 lines
947 B
C
#include "src.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
void c12() {
|
|
int num_elements;
|
|
printf("Enter number of elements (Calloc): ");
|
|
scanf("%d", &num_elements);
|
|
// Allocate the needed memory
|
|
int *elements = calloc(num_elements, sizeof(int));
|
|
|
|
// 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();
|
|
c12();
|
|
return 0;
|
|
}
|