-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscratch.c
More file actions
40 lines (33 loc) · 791 Bytes
/
Copy pathscratch.c
File metadata and controls
40 lines (33 loc) · 791 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const char *hello = "hello";
int main(void)
{
int *num = (int *)malloc(sizeof(int));
if (num == NULL) {
exit(1);
}
*num = 42;
printf("Num Init: %d\n", *num);
free(num);
num = NULL;
int *num_of_three = (int *)malloc(sizeof(int) * 3);
if (num_of_three == NULL) {
exit(1);
}
int nums[3] = {10, 20, 30};
for (int i = 0; i < 3; i++) {
num_of_three[i] = nums[i];
printf("Num of three: idx - %d \n value - %d \n", i, num_of_three[i]);
}
size_t hello_len = strlen(hello);
char *copy = malloc(hello_len + 1);
if (copy == NULL) {
exit(1);
}
strcpy(copy, hello);
printf("%s\n", copy);
free(copy);
copy = NULL;
}