In: Computer Science
Create C program that takes 1 parameter: a number.
Using that number, dynamically allocate a memory so you store that number of integers.
Write integers in order starting from 1 until you fill all that memory.
Print the addresses and values of the first and the last integer stored in the memory.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int n=atoi(argv[1]);
int *array = (int*)malloc(n*sizeof(int));
for(int i=0;i<n;i++)
{
*(array+i)=(i+1);
}
printf("Address of first integer: %p and Value of first integer:
%d\n",&array[0],array[0]);
printf("Address of last integer: %p and Value of last integer:
%d\n",&array[n-1],array[n-1]);
return 0;
}