-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpointer_functions.c
72 lines (56 loc) · 1.08 KB
/
pointer_functions.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Basic Pointer Functions
void *alloc_pointer(void)
{
int *a = malloc(sizeof(int));
return a;
}
void write_int_pointer(int to_write, void *ptr)
{
*(int *)ptr = to_write;
}
int read_int_pointer(void *ptr)
{
return *(int *)ptr;
}
void free_pointer(void *pt)
{
free(pt);
}
// Array int primitives
void *create_int_array_long(double size)
{
return malloc(sizeof(int) * size);
}
void *create_int_array(int size)
{
return malloc(sizeof(int) * size);
}
void write_int_array_long(double loc, int item, void *ptr)
{
((int *)ptr)[(long long)loc] = item;
}
void write_int_array(int loc, int item, void *ptr)
{
((int *)ptr)[loc] = item;
}
int read_int_array(int loc, void *ptr)
{
return ((int *)ptr)[loc];
}
// Free remains the same
// Array Primitives for Char
void *create_char_array(int size)
{
return malloc(sizeof(char) * size);
}
void write_char_array(int loc, char item, void *ptr)
{
((char *)ptr)[loc] = item;
}
char read_char_array(int loc, void *ptr)
{
return ((char *)ptr)[loc];
}