-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday23.c
98 lines (88 loc) · 3.85 KB
/
day23.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <stdio.h>
int main()
{
;
// int a = 34;
// char b = '3';
// int *ptra = &a;
// char *ptrb = &b;
// ptra++;
// ptra--;
// ptrb++;
// ptrb--;
// printf("%d\n", ptra);
// printf("%d\n", ptra + 1); // 1 size of int = 4
// printf("%d\n", ptra + 2); // 2 size of int = 8
// printf("%d\n", ptrb);
// printf("%d\n", ptrb + 1); // 1 size of char = 1 byte
// printf("%d\n", ptrb + 2); // 2 size of char = 2 byte
// printf("%d\n", ptra);
// printf("%d\n", ptra - 1); // 1 size of int = 4
// printf("%d\n", ptra - 2); // 2 size of int = 8
// printf("%d\n", ptrb);
// printf("%d\n", ptrb - 1); // 1 size of char = 1 byte
// printf("%d\n", ptrb - 2); // 2 size of char = 2 byte
// printf("%d\n", ptra);
// printf("%d\n", ptrb);
// char a = '3';
// char *ptra = &a;
// printf("%d\n", ptra);
// ptra++; Adds the value by +1
// printf("%d\n", ptra); Prints the value by +1
// printf("%d\n", ptra - 2); Subtracts the value by -1
// Program in hexadecimal format
// char a = '3';
// char *ptra = &a;
// printf("%x\n", ptra);
// ptra++;
// printf("%x\n", ptra);
// printf("%x", ptra - 2);
// char a = '3';
// char *ptra = &a;
// printf("%p\n", ptra);
// ptra++;
// printf("%p\n", ptra);
// printf("%p", ptra - 2);
// char a = '3';
// char *ptra = &a;
// printf("%d\n", ptra);
// ptra--;
// printf("%d\n", ptra);
// printf("%d", ptra - 2);
// char a = '3';
// char *ptra = &a;
// printf("%x\n", ptra);
// ptra--;
// printf("%x\n", ptra);
// printf("%x", ptra - 2);
// char a = '3';
// char *ptra = &a;
// printf("%p\n", ptra);
// ptra--;
// printf("%p\n", ptra);
// printf("%p", ptra - 2);
int arr[] = {311, 52, 3, 4, 5, 6, 7, 67};
int *arrayptr = arr;
printf("%d \n", arr[0]);
printf("Value at position 3 of the array is %d\n", arr[3]);
printf("The address of first element of the array is %d \n", &arr[0]);
printf("The address of first element of the array is %d \n", arr); // the address of the first element prints by default
printf("The address of second element of the array is %d \n", &arr[1]);
printf("The address of second element of the array is %d \n", arr + 1); // prints the same line and the same address of the next index
printf("The address of third element of the array is %d \n", &arr[2]);
printf("The address of third element of the array is %d \n", arr + 2); // prints the same line and the same address of the next index
arrayptr++;
arrayptr--;
// arr++; or arr--; is a constant and you cannot change it; will throw an error since the first element contains an index number [0] address
// dereferencing the value
printf("The value at address of first element of the array is %d \n", *(&arr[0]));
printf("The value at address of first element of the array is %d \n", *(arr)); // the address of the first element prints by default
printf("The value at address of first element of the array is %d \n", arr[0]); // the address of the first element prints by default
printf("The value at address of second element of the array is %d \n", *(&arr[1]));
printf("The value at address of second element of the array is %d \n", arr[1]);
printf("The value at address of second element of the array is %d \n", *(arr + 1)); // prints the same line and the same address of the next index
printf("The value at address of third element of the array is %d \n", *(arr + 2)); // prints the same line and the same address of the next index
printf("The value at address of third element of the array is %d \n", arr[2]);
printf("The value at address of third element of the array is %d \n", *(&arr[2]));
return 0;
}