Variable size/Get
Variable size/Get
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
Demonstrate how to get the size of a variable.
Ada
Ada represents the size of a variable in bits, not bytes like many other languages.
Int_Bits : constant Integer := Integer'size; Whole_Bytes : constant Integer := Int_Bits / Storage_Unit; -- Storage_Unit is the number of bits per storage element
IDL
IDL is array based, so its size() function is geared towards that:
arr = intarr(3,4) print,size(arr) ;=> prints this: 2 3 4 2 12
The result means: 2 dimensions in the array, the first dimension has extent 3, the second has extent 4, the elements of the array are 2-byte integers (IDL's default for an "int"), there's a total of 12 elements in the array.
Tcl
Since all variables are ultimately strings in Tcl, this is easy:
string bytelength $var