What is an array's ptr property in D programming?

Overview

An array’s ptr property in D returns the pointer of an array’s first element.

Syntax

array.ptr

Return value

The value returned is a pointer value of the array’s first element.

Example

// import std.stdio
import std.stdio;
// main method
void main(string[] args) {
// create an array
string[3] languages;
// add values
languages[0] = "D";
languages[1] = "Swift";
languages[2] = "C#";
// print the pointer of first element
writeln(languages.ptr);
}

Explanation

  • Line 7: We create an array.
  • Lines 9-11: We allocate the array some values.
  • line 14: We print the first statement’s pointer.

Free Resources