source:
CIVL/examples/languageFeatures/pointers.cvl@
475b2d9
| Last change on this file since 475b2d9 was 793cfc2, checked in by , 13 years ago | |
|---|---|
|
|
| File size: 339 bytes | |
| Rev | Line | |
|---|---|---|
| [6543229] | 1 | #include<civlc.h> |
| 2 | ||
| [40a899c] | 3 | void passByRef(int * array) { |
| 4 | *array = 42; | |
| 5 | } | |
| 6 | ||
| [6543229] | 7 | void main() { |
| 8 | int a; | |
| 9 | int* b; | |
| 10 | int c[2]; | |
| 11 | int* d; | |
| [b6565a0] | 12 | int** g; |
| [40a899c] | 13 | int* f; |
| [b6565a0] | 14 | |
| [40a899c] | 15 | f = &a; |
| [6543229] | 16 | a = 1; |
| 17 | b = &a; | |
| 18 | c[0] = 0; | |
| 19 | c[1] = 1; | |
| 20 | d = &c[1]; | |
| [b6565a0] | 21 | g = &d; |
| [6543229] | 22 | $assert *b == 1; |
| 23 | $assert *d == 1; | |
| [b6565a0] | 24 | $assert **g == 1; |
| [40a899c] | 25 | $assert g == &d; |
| 26 | passByRef(f); | |
| 27 | $assert *f == 42; | |
| [6543229] | 28 | } |
Note:
See TracBrowser
for help on using the repository browser.
