-
Notifications
You must be signed in to change notification settings - Fork 0
/
play_pointers.c
56 lines (42 loc) · 900 Bytes
/
play_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
51
52
53
54
#include <stdio.h>
#include <stdlib.h>
void display(int arr[], int num){
for (int i = 0; i < num ; i++){
printf("%d\t%d\t%p\n",i,arr[i]*arr[i]-arr[i],&arr[i]);
}
}
void display_reverse(int arr[], int num){
for (int i = 0 ; i < num ; i++) {
arr[i] = num - i;
}
}
void swap(int *a, int *b){
int temp;
temp = *a;
*a = *b;
*b = temp;
}
int main(int argc, char** argv){
int *px = NULL;
int x = 100;
px = &x;
printf("x:\t%d\npx:\t%p\n&x:\t%p\n*px:\t%d\n",x,px,&x,*px);
int n = 6;
int *array;
array = malloc(n * sizeof(int));
for (int i = 0 ; i < n ; i++) array[i] = i;
display(array,n);
printf("\n%p\n",array);
printf("%p\n",&array[0]);
int c,d;
c = 10;
d = 20;
printf("\n%d\t%d\n",c,d);
swap(&c,&d);
printf("%d\t%d\n",c,d);
printf("\n%d\t%d\n",array[0],array[3]);
display_reverse(array,n);
printf("%d\t%d\n",array[0],array[3]);
free(array);
return 0;
}