-
Notifications
You must be signed in to change notification settings - Fork 0
/
pointers.cxx
60 lines (47 loc) · 1.07 KB
/
pointers.cxx
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
#include <stdio.h>
/*
* Programa que calcula el area de distitos cuerpos geometricos
*/
int main()
{
int a = 5;
int b = 10;
int *p1;
int *p2;
p1 = &a;
p2 = &b;
*p1 = 10;
p1 = p2;
*p1 = 20;
printf("a = %d\n", a);
printf("b = %d\n", b);
int arr[5] = {1,2,3,4,5};
*p1;
p1 = &arr[1]; // gets address of this element
printf("*p1 = %d\n", *p1);
p1++; // point to the next element
printf("*p1 = %d\n", *p1);
*p2;
p1 = &arr[1];
p2 = p1++;
printf("*p2 = %d\n", *p2);
p1 = &arr[1];
printf("*p1 = %d\n", *p1);
p1 = p1+2;
printf("*p1 = %d\n", *p1);
p1 = &arr[1];
int dave;
dave = *(p1+2);
printf("*p1 = %d\n", *p1);
printf("dave = %d\n", dave);
int **ramon;
int *paul;
int melissa = 5;
paul = &melissa;
ramon = &paul;
printf("ramon = %d\n", ramon);
printf("&paul = %d\n", &paul);
printf("*ramon = %d\n", *ramon);
printf("&melissa = %d\n", &melissa);
printf("**ramon = %d\n", **ramon);
}