File: array_zero.ck

package info (click to toggle)
chuck 1.5.5.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 41,056 kB
  • sloc: cpp: 123,473; ansic: 35,893; javascript: 2,111; yacc: 609; makefile: 457; python: 174; perl: 86
file content (37 lines) | stat: -rw-r--r-- 807 bytes parent folder | download
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
// .zero() zeros out the contents AND keeps size unchanged
// version: need chuck-1.5.0.0 or higher
//
// NOTE: using .zero() with multidimensional arrays
//       requires chuck-1.5.5.1 or higher

// an array
[1,3,4] @=> int array[];

// should print 3 3
<<< array[1], array.size() >>>;

// zero out the array, leaving size as is
array.zero();

// now should print 0 3
<<< array[1], array.size() >>>;

// a multi-dimensional array
[ [1,2], [3,4] ] @=> int array2[][];

// NOTE: using .zero() with multidimensional arrays
//       requires chuck-1.5.5.1 or higher
array2.zero();

// iterate over array2
for( int inner[] : array2 )
{
    // iterate over each inner array
    for( int x: inner )
    {
        // print each element within
        cherr <= x <= " ";
    }
}
// print newline
cherr <= IO.nl();