-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC_Pointer_And_Address.c
44 lines (37 loc) · 1.04 KB
/
C_Pointer_And_Address.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
#include <stdio.h>
int main() {
/*
Pointers and Adress
Pointer = referencing a value to a variable
Address = the memory that holds a value
* means pointer
& address of the variable
Example:
Adress Value Equivalent in programming (C) language
0X1234 4 int x = 4;
0X2345 0X1234 int *y = &x
0X3456 int z;
*/
// No pointer or address
int a = 5;
int b = a; // An independent copy
a += 2; // We add 2 to a, but b is still 5
printf("Without pointer or address\n");
printf("Value of a is %d\n", a);
printf("Value of b is %d, an independent copy from a\n", b);
printf("Even if you changed the value of a, b would not change\n\n");
// With pointer and address
int c = 10;
int *d = &c; // Points a reference to the address of c
/*
integer pointer d is set to the address of c
*/
printf("Value of c is %d\n",c);
printf("Value of d is %d\n",*d);
printf("If we change the value of c:\n");
c += 3; // Add 3 to c
printf("Value of c is %d\n",c);
printf("Value of d is %d\n",*d);
getchar();
return 0;
}