This repository has been archived on 2023-10-26. You can view files and clone it, but cannot push or open issues or pull requests.
VSMechatronics/C16/ex3.c
2023-10-06 16:59:12 +01:00

24 lines
424 B
C

#include <stdio.h>
#include <stdlib.h>
int main(void)
{
// Declare an integer array and an integer pointer
int *pData;
int datlen;
printf("Length of data to be allocated: ");
scanf("%d", &datlen);
// Using malloc
pData = malloc ( datlen * sizeof (int));
for (int i = 0; i < datlen; i++) {
pData[i] = i;
printf("%d %d\n", i, i);
}
free(pData);
return 0; // Exit
}