about array setting

Bill Baxter dnewsgroup at billbaxter.com
Fri Jan 19 22:17:18 PST 2007


dfun wrote:
> about array setting
> on this page http://www.digitalmars.com/d/arrays.html
> give an example
> 

The examples are assuming you do something like allocate p inbetween the 
declaration and usage lines.

> int[3] s;
> int* p;

--  need something like  p = new int[3]; here.

> s[] = 3;		// same as s[0] = 3, s[1] = 3, s[2] = 3
> p[0..2] = 3;		// same as p[0] = 3, p[1] = 3
> 
> pring error => Error: Access Violation
> why?
> use dmd 1.0

It's clear to you that this is an error, right?

int *p;
p[0] = 3;
p[1] = 3;

The slice operation on p does the same thing.  p is initialized to a 
null pointer, so you're dereferencing a null pointer.
--bb



More information about the Digitalmars-d mailing list