-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_pointers.c
50 lines (41 loc) · 1.22 KB
/
data_pointers.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
/* Program to understand the pointers concept in 'c' language */
#include <stdio.h>
#ifdef DEBUG
#undef DEBUG
#else
#define MAN_DEBUG
#endif
int main (void) {
char alpha = 'A';
/* A character pointer that holds the address of alpha or
holds the address of a memory whose value can be accessed
as character through pointer (alpha_ptr)
*/
char *alpha_ptr = α
#if defined DEBUG
printf("val: %p\n", alpha_ptr);
printf("val: %p\n", &alpha);
printf("val: %p\n", &alpha_ptr);
printf("val: %c\n", *alpha_ptr);
#endif
int *alpha_ptr_2 = (int *)α
#if defined DEBUG
printf("val: %p\n", alpha_ptr_2);
printf("val: %p\n", &alpha);
printf("val: %p\n", &alpha_ptr_2);
printf("val: %x\n", *alpha_ptr_2);
#endif
int **alpha_ptr_3 = &alpha_ptr_2;
#if defined DEBUG
printf("val: %p at line %d\n",alpha_ptr,__LINE__);
printf("val: %p at line %d\n",alpha_ptr_2, __LINE__);
printf("va;: %p at line %d\n",&alpha_ptr_2, __LINE__);
printf("val: %p at line %d\n", alpha_ptr_3, __LINE__);
#endif
#ifdef MAN_DEBUG
printf("val: %c at line %d\n",alpha,__LINE__);
printf("val: %c at line %d\n", *alpha_ptr_2, __LINE__);
printf("val: %c at line %d\n", **alpha_ptr_3, __LINE__);
#endif
return 0;
}