I was able to find some information on C, Perl, and even a little on Ada, but was wondering if some people in the community could offer their own input as well.
-------------------------------------------------------------------
On Exforsys I found the following with regards to C (which of course is similar to the next gen C#):
Declaring Single Dimension Arrays
<data type> array_name[size_of_array]; char game_map[4]; int emp_code[3];
Can be initialized 2 ways, on Declaration or by Assignment:
Declaration:
<data type> array_name[size_of_array] = {element 1, element 2, ...};
char game_map[3] = {'S', 'R', 'D'};
Assignment
char game_map[3]; game_map[0] = 'S'; game_map[1] = 'R'; game_map[2] = 'D';
Accessing Single Dimensional Array Elements:
array_name[index_of_element]; array_name[index_of_element] = value; game_map[0]; //value of 'S' game_map[1]; //value of ' R' game_map[2]; //value of 'D'
Quote
Trying to access a value outside the bounds of index 1 through size_of_array – 1, results in runtime errors. Your compiler will not complain, but your program will crash when it executes.
will lead to a runtime error and you program would crash because you tried to access a memory location outside the bound of the array, otherwise known as a segmentation fault.
game_map[3];
will lead to a runtime error and you program would crash because you tried to access a memory location outside the bound of the array, otherwise known as a segmentation fault.
---------------------------------------------------------------------------
PERL Arrays
Initialization:
@array = ( 1, 2, 3 ); @array = function_generating_a_list(); @array = @another_array;
Quote
The key points are that the assignment to an array gives list context to the right hand side; the right side can be any expression which results in a list of zero or more scalar values. The values are inserted in the array in the same order as they occur in the list, beginning with array index zero. For example, after executing
element 0 will contain 'a', element 1 will contain 'b', and so on.
Whenever an array is assigned to en masse like this, any contents it may have had before the assignment are removed!
@array = ( 'a', 'b', 'c' );
element 0 will contain 'a', element 1 will contain 'b', and so on.
Whenever an array is assigned to en masse like this, any contents it may have had before the assignment are removed!
Quote
Accessing Elements in Array
The first element of an array is accessed at index 0:
Get count of elements
To get the "length" or "size" of an array, simply use it in a scalar context. For example, you can "assign" the array to a scalar variable:
and the scalar variable will afterwards contain the count of elements in the array. Other scalar contexts work as well:
(Yes, print gives its arguments list context, but the dot (string concatenation) operator takes precedence.)
You can always force scalar context on an array by using the function named scalar:
The first element of an array is accessed at index 0:
$first_elem = $array[0];
Get count of elements
To get the "length" or "size" of an array, simply use it in a scalar context. For example, you can "assign" the array to a scalar variable:
$count = @array;
and the scalar variable will afterwards contain the count of elements in the array. Other scalar contexts work as well:
print "# Elements: " . @array . "\n";
(Yes, print gives its arguments list context, but the dot (string concatenation) operator takes precedence.)
You can always force scalar context on an array by using the function named scalar:
print "# Elements: ", scalar(@array), "\n";
Quote
Get the highest index
Often, you want to know what is the highest index in an array — that is, the index of its last element. Perl provides a special syntax for obtaining this value:
Often, you want to know what is the highest index in an array — that is, the index of its last element. Perl provides a special syntax for obtaining this value:
$highest_index = $#array;
Quote
Remove an element from the end
The function to remove a single element from the end of an array is pop. Given the code:
$x will contain 'c' and @array will be left with two elements, 'a' and 'b'.
The function to remove a single element from the end of an array is pop. Given the code:
@array = ( 'a', 'b', 'c' ); $x = pop @array;
$x will contain 'c' and @array will be left with two elements, 'a' and 'b'.
Quote
Remove an element from the beginning
The shift function removes one value from the beginning of the array. That is, it removes (and returns) the value in element zero, and shifts all the rest of the elements down one, with the effect that the number of elements is decreased by one. Given the code:
The shift function removes one value from the beginning of the array. That is, it removes (and returns) the value in element zero, and shifts all the rest of the elements down one, with the effect that the number of elements is decreased by one. Given the code:
@array = ( 'a', 'b', 'c' ); $x = shift @array;
------------------------------------------------------------------------------------------
Searched: ADA
Array Declaration:
procedure demo is
squares: array (1 .. 10) of integer;
begin
for i in 1 .. 10 loop
squares(i) := i ** 2;
end loop;
end demo;
Aggregate Assignment:
procedure demo is
squares: array (1 .. 5) of integer;
begin
squares := (1, 4, 9, 16, 25); -- aggregate assignment
for i in 1 .. 10 loop
put(squares(i));
end loop;
end demo;
Array Attributes:
Attributes of array types:
- 'first
- 'last
- 'range
- 'length
Attributes of array variables:
- 'first
- 'last
- 'range
- 'length
Attributes allow code to be written that is independent of the array bounds.

New Topic/Question
Reply


MultiQuote



|