source: CIVL/examples/languageFeatures/pointerAdd.cvl@ 81b9329

1.23 2.0 main test-branch
Last change on this file since 81b9329 was d96f2926, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

minor correction.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@909 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.0 KB
Line 
1#include <civlc.h>
2#include <stdio.h>
3
4void main(){
5 double * p1d;
6 double ** p2d;
7 double a1d[10];
8 double a2d[10][10];
9
10 p1d = (double *)$malloc($root, sizeof(double) * 10);
11 p2d = (double **)$malloc($root, sizeof(double *) * 10);
12 for(int i=0; i<10; i++){
13 a1d[i] = i;
14 p2d[i] = (double *)$malloc($root, sizeof(double) * 10);
15 for(int j=0; j<10; j++){
16 a2d[i][j] = i * 10 + j;
17 p2d[i][j] = i * 10 + j;
18 }
19 }
20
21 /* access array */
22 printf("*(a1d + 5) = %.4f\n", *(a1d + 5));
23 printf("*(a1d + 9) = %.4f\n", *(a1d + 9));
24 printf("*(*(a2d + 5) + 5) = %.4f\n", *(*(a2d + 5) + 5));
25 printf("*(&a2d[0][0] + 10) = %.4f\n", *(&a2d[0][0] + 10));
26 printf("*(&a2d[0][0] + 99) = %.4f\n", *(&a2d[0][0] + 99));
27
28 /* access malloced pointer */
29 printf("*(p1d + 5) = %.4f\n", *(p1d + 5));
30 printf("*(p1d + 9) = %.4f\n", *(p1d + 9));
31 printf("*(*(p2d + 5) + 5) = %.4f\n", *(*(p2d + 5) + 5));
32 printf("*(&p2d[0][0] + 10) = %.4f\n", *(&p2d[0][0] + 10));
33 printf("*(*p2d + 9) = %.4f\n", *(*p2d + 9));
34}
Note: See TracBrowser for help on using the repository browser.