c16
This commit is contained in:
parent
7bb7fc04b1
commit
8b1303304d
18
C16/ex2.c
Normal file
18
C16/ex2.c
Normal file
@ -0,0 +1,18 @@
|
||||
#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));
|
||||
|
||||
free(pData);
|
||||
return 0; // Exit
|
||||
}
|
23
C16/ex3.c
Normal file
23
C16/ex3.c
Normal file
@ -0,0 +1,23 @@
|
||||
#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
|
||||
}
|
Reference in New Issue
Block a user