Array length: Difference between revisions

Content added Content deleted
No edit summary
Line 167: Line 167:
=={{header|Ada}}==
=={{header|Ada}}==


<syntaxhighlight lang="ada">with Ada.Text_IO; use Ada.Text_IO;
<syntaxhighlight lang="ada">
with Ada.Text_IO; use Ada.Text_IO;
with System;


procedure Array_Length is
procedure Array_Length is

Fruits : constant array (Positive range <>) of access constant String
Fruits : constant array (Positive range <>) of access constant String
:= (new String'("orange"),
:= (new String'("orange"),
new String'("apple"));
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);
Put_Line ("Array memory Size : " & Memory_Size'Image & " bytes" );
Put_Line (" " & Integer'Image (Memory_Size * System.Storage_Unit / System.Word_Size) & " words" );
end Array_Length;</syntaxhighlight>
end Array_Length;</syntaxhighlight>


{{out}}
{{out}}
<pre>
<pre> 6 5 Array Size: 2</pre>
Number of elements : 2
Array memory Size : 32 bytes
4 words
</pre>


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==