Array length: Difference between revisions

No edit summary
Line 167:
=={{header|Ada}}==
 
<syntaxhighlight lang="ada">with Ada.Text_IO; use Ada.Text_IO;
with Ada.Text_IO; use Ada.Text_IO;
with System;
 
procedure Array_Length is
 
Fruits : constant array (Positive range <>) of access constant String
:= (new String'("orange"),
new String'("apple"));
 
Memory_Size : constant Integer := Fruits'Size / System.Storage_Unit;
begin
for Fruit of Fruits loop
Ada.Text_IO.Put (Integer'Image (Fruit'Length));
end loop;
 
begin
Ada.Text_IO.Put_Line (" Array Size : " & Integer'Image (Fruits'Length));
Put_Line ("Number of elements : " & Fruits'Length'Image);
Ada.Text_IO.Put_Line (" Array memory Size : " & IntegerMemory_Size'Image (Fruits'Length)& " bytes" );
Put_Line (" " & Integer'Image (Memory_Size * System.Storage_Unit / System.Word_Size) & " words" );
end Array_Length;</syntaxhighlight>
 
{{out}}
<pre>
<pre> 6 5 Array Size: 2</pre>
Number of elements : 2
Array memory Size : 32 bytes
4 words
</pre>
 
=={{header|ALGOL 68}}==