-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrays-1.C
48 lines (43 loc) · 887 Bytes
/
arrays-1.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
#include<stdio.h>
#include<stdlib.h>
struct myArray
{
int total_size;
int used_size;
int * ptr;
};
void createArray(struct myArray * a, int tSize, int uSize)
{
// (*a).total_size=tSize;
// (*a).used_size=uSize;
// (*a).ptr = (int *) malloc(tSize*sizeof(int));
//the above written code is similar to the one below
a->total_size = tSize;
a->used_size = uSize;
a->ptr = (int *)malloc(tSize*sizeof(int));
}
void setVal (myArray *a)
{
for(int i=0; i<a->used_size;i++)
{
int n;
printf("Enter Element %d", i);
scanf("%d", &n);
(a->ptr)[i] = n;
}
}
void show(struct myArray *a)
{
for (int i = 0; i < a->used_size; i++)
{
printf("%d\n", (a->ptr)[i]);
}
}
int main()
{
struct myArray marks;
createArray(&marks, 10,2);
setVal(&marks);
show(&marks);
return 0;
}