-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathmalloc.c
44 lines (41 loc) · 788 Bytes
/
malloc.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
# include<stdio.h>
# include<stdlib.h>
void read(int N,int *ptr);
void display(int N,int *ptr);
int main()
{
int *ptr;
int n;
printf("enter the size of array:");
scanf("%d",&n);
ptr=(int*)malloc(n*sizeof(int));
if(ptr==NULL)
{
printf("memory not allocated");
exit(0);
}
else
{
read(n,ptr);
display(n,ptr);
free(ptr);
}
}
void read(int N,int *ptr)
{
int i;
printf("enter the elements:");
for(i=0;i<N;i++)
{
scanf("%d",&ptr[i]);
}
}
void display(int N,int*ptr)
{
int i;
printf("displaying elements:");
for ( i = 0; i < N; i++)
{
printf("%d ",ptr[i]);
}
}