Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

d
communitycreator

What is the sizeof property of an array in D?

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The sizeof property of an array in the D programming language is used to get the array length multiplied by the number of bytes per array element.

Syntax

array.sizeof

Return value

This method returns an integer that represents the result of multiplying the array length by the number of bytes per array element.

Code example

// import std.stdio
import std.stdio;
// main method
void main(string[] args) {
// create an array
int[3] ages;
// add values
ages[0] = 18;
ages[1] = 34;
ages[2] = 50;
// print the length of the array
writeln(ages.sizeof);
}
Using the "sizeof" property of an array

Code explanation

  • Line 2: We import the std library.
  • Line 5: We create the main method.
  • Lines 9–11: We give values to the elements of the array.
  • Line 14: We call the sizeof property on the array, and print the result to the console.

RELATED TAGS

d
communitycreator

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring