-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcallocDynamicMemoryFunc.c
56 lines (39 loc) · 983 Bytes
/
callocDynamicMemoryFunc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<stdio.h>
#include<stdlib.h>
void main()
{
float *ptr; // float pointer
int n;
printf("Enter any number :");
scanf("%d",&n);
ptr = (float*) calloc(n , sizeof(float)); // calloc function . . .
printf("Enter %d numbers into array : ",n);
for(int i=0 ; i<n ; i++)
{
scanf("%f" , &ptr[i]);
}
for(int i=0 ; i<n ;i++)
{
printf("%f\t" , ptr[i]);
}
printf("\n");
int m;
printf("Enter any number : \n");
scanf("%d",&m);
ptr = realloc(ptr , m); // realloc function . . .
printf("Enter %d numbers : " , m);
for(int i=0 ; i<m;i++)
{
scanf("%f",&ptr[i]);
}
for(int i=0 ; i<m ; i++)
{
printf("%d index of = %f\n",i,ptr[i]);
}
printf("Number are available into array are");
free(ptr); // free function . .
for(int i ; i<m ; i++)
{
printf("%f\t",ptr[i]);
}
}