Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changes from Version 1 of ReturningArraysFromFunctionsExample

Show
Ignore:
Author:
jcc7 (IP: 68.97.93.38)
Timestamp:
11/12/05 04:19:11 (18 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ReturningArraysFromFunctionsExample

    v0 v1  
     1= Returning Arrays from Functions = 
     2 
     3''Part of'' ArraysCategory 
     4 
     5== Description == 
     6 
     7Shows how to return arrays from functions. 
     8 
     9== Example == 
     10 
     11{{{ 
     12#!d 
     13int[] someFunction() /* dynamic array */  
     14{ 
     15    int[] i; 
     16 
     17    i.length = 5; 
     18    i[0] = 1; 
     19    i[1] = 1; 
     20    i[2] = 2; 
     21    i[3] = 3; 
     22    i[4] = 5; 
     23    return i; 
     24} 
     25 
     26 
     27struct fa_int5  /* struct wrapper */ 
     28{ 
     29    int[5] i; /* static array */ 
     30} 
     31 
     32 
     33fa_int5 someFunction2() 
     34{ 
     35    fa_int5 k; 
     36 
     37    k.i[0] = 1; 
     38    k.i[1] = 1; 
     39    k.i[2] = 2; 
     40    k.i[3] = 3; 
     41    k.i[4] = 5; 
     42    return k; 
     43} 
     44 
     45 
     46void main() 
     47{ 
     48    int[] j = someFunction(); 
     49    fa_int5 m; 
     50 
     51    m = someFunction2(); 
     52    int[5] n = m.i; 
     53} 
     54}}} 
     55 
     56== Source == 
     57 
     58|| Link || http://www.dsource.org/tutorials/index.php?show_example=86 || 
     59|| Posted by || jcc7 || 
     60|| Date/Time || Sun Jun 27, 2004 10:04 pm ||