-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynamic_2d_array.cpp
95 lines (47 loc) · 1.31 KB
/
dynamic_2d_array.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <stdio.h>
#include<stdlib.h>
int x=3,y,i,j;
int main(){
int **tab1;
printf("the first adresse : %d\n\n\n\n",tab1);
tab1=(int**)malloc(sizeof(int*)*x);
// the adress of the pointers of a pointer
for(i=0;i<x;i++)
printf("pointer : %d adrees: %d\n",*(tab1+i),&*(tab1+i));
printf("donnez :");
scanf("%d",&y);
printf("before making the 2d\n");
for(i=0;i<x;i++)
printf("pointer : %d adrees: %d\n",*(tab1+i),&*(tab1+i));
for(i=0;i<x;i++)
tab1[i]=(int*)malloc(sizeof(int)*y);
printf("after making the 2d\n");
for(i=0;i<x;i++)
printf("pointer : %d adrees: %d\n",*(tab1+i),&*(tab1+i));
//remplir
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
printf("donnez l\'element de line %d collon %d whish has the adress %d : ",i+1,j+1,*(tab1+i)+j);
scanf("%d",*(tab1+i)+j);
}
}
printf("with &\n");
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
printf("*tab1[%d][%d]=%ld ",i+1,j+1,&tab1[i][j]);
printf("\n\n");
}
printf("with *\n");
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
printf("*(tab1+%d*y+%d)=%ld ",i+1,j+1,(*(tab1+i)+j));
printf("\n\n");
}
for(i=0;i<x;i++)
free(tab1[i]);
free(tab1);
}