View difference between Paste ID: DNA6h60t and xe6nKJQP
SHOW: | | - or go back to the newest paste.
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <malloc.h>
4
5
#define DELTA 33
6
7
int calls, seed=356;   
8
9-
int soma_ds(int a){     
9+
int sum_ds(int a){     
10
 int d=DELTA;          
11
 calls++; 				
12
 return a+d+seed;
13
}   					
14
15
int main() {
16
	printf("calls has the value: %d and is at address 0x%08X\n",calls,&calls);
17
	printf("seed has the value: %d and is at address 0x%08X\n",seed,&seed);
18
19
	int num;								
20
	int *ptr;
21
	int **handle;
22
23
	printf("------------------\n");
24
	printf("num is at address 0x%08X and has the value: %d\n",&num,num);
25
	printf("ptr is at address 0x%08X, pointing to 0x%08X, and has the value: %d\n ",&ptr,ptr,*ptr);
26
	printf("------------------\n");
27
	/*printf("handle is at address 0x%08X, pointing to 0x%08X, and has the value: %d\n ",&handle,handle,*handle);*/
28
29
	num = 14;								
30
	printf("num is at address 0x%08X and has the value: %d\n",&num,num);
31
32
	ptr = (int *)malloc(2 * sizeof(int));	
33
	printf("ptr is at address 0x%08X, pointing to 0x%08X, and has the value: %d\n",&ptr,ptr,*ptr);
34
35
	handle = &ptr;							
36
	/*printf("handle is at address 0x%08X\n",&handle);*/
37
	/*printf("handle is at address 0x%08X, pointing to 0x%08X, and has the value: %d\n ",&handle,handle,*handle);*/
38
39
	*(*handle+0) = num;					
40
	printf("------------------\n");
41
	printf("This is a test to see what's *handle+0: 0x%08X\n",*handle+0);
42
	printf("This is a test to see what's *(*handle+0) value: %d and address 0x%08X\n",*(*handle+0),&*(*handle+0));
43
	printf("------------------\n");
44
	/*printf("handle is at address 0x%08X, pointing to 0x%08X, and has the value: %d\n ",&handle,handle,*handle);*/
45
46
	*(*handle+1) = num+1;					
47
	/*printf("handle is at address 0x%08X, pointing to 0x%08X, and has the value: %d\n ",&handle,handle+1,*handle+1);*/
48
	printf("------------------\n");
49
	printf("This is a test to see what's *handle+1: 0x%08X\n",*handle+1);
50
	printf("This is a test to see what's *(*handle+1) value: %d and address 0x%08X\n",*(*handle+1),&*(*handle+1));
51
	printf("------------------\n");
52
53
	*ptr = num-2;							
54
	printf("ptr is at address 0x%08X, pointing to 0x%08X, and has the value: %d\n",&ptr,ptr,*ptr);
55
56
	ptr = &num;							
57
	printf("ptr is at address 0x%08X, pointing to 0x%08X, and has the value: %d\n",&ptr,ptr,*ptr);
58
59-
	*ptr = soma_ds(num-2);					
59+
	*ptr = sum_ds(num-2);					
60
	printf("ptr is at address 0x%08X, pointing to 0x%08X, and has the value: %d\n",&ptr,ptr,*ptr);
61
	printf("The value of num must be the same as pointed by prt %d", num);
62
63
	return 0;
64
}