-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpt2array.c
More file actions
64 lines (46 loc) · 1.12 KB
/
Copy pathpt2array.c
File metadata and controls
64 lines (46 loc) · 1.12 KB
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
/* Pointers and arrays */
#include <stdio.h>
int main(){
int i,j,row,col;
int *pA;
float *pB;
int *pC;
int a[]={5,10,15,20,25};
pA = &a[0];
printf("%d\n",a[0]);
printf("%d %d\n",*pA, *(pA+1));
printf("Second test\n");
/* Another test */
float b[] = {5.1,10.2,15.3,20.4,25.5};
pB = b;
printf("pB value is: %f\n",*pB);
int c[3][4] = {
{10,11,12,13},
{14,15,16,17},
{18,19,20,21}
}; /* 2D array declaration and initialization*/
pC = &c[0][0];
printf("pC address= %d\n",*pC);
/* print ut all elements of b[] */
for(i=0;i<5;i++){
printf("%.2lf ",*(pB+i));
}
printf("\n\nPrint a 2D array:\n");
for(row=0;row<3;row++){
for(col=0;col<4;col++){
printf("%d ",c[row][col]);
}
printf("\n");
}
printf("\n");
printf("Using pointers\n");
int d=0;
for(i=0;i<3;i++){
for(j=0;j<4;j++){
printf("%d ",*(pC+i+j+d));
}
d += 3;
printf("\n");
}
return 0;
}