Robert Jacques wrote:
>On Tue, 03 May 2011 08:20:42 -0400, Bruno Medeiros
><brunodomedeiros+spam@com.gmail> wrote:
>
>> On 27/04/2011 22:20, Timon Gehr wrote:
>>> Quiz: What does the following code compute?
>>>
>>> import std.stdio;
>>> import core.exception;
>>> void main(){
>>>  int a,b;
>>>  int[int] aa;
>>>  scanf("%d %d",&a,&b);
>>>  try{aa[a]=aa[b];printf("Y\n");}catch(RangeError){printf("N\n");}
>>> }
>>
>> What was your point here? Is there even any way an associative array
>> throws a RangeError?
>
> An AA throws a range error if the key is not in the AA during an index
> operation. Since aa is initialized, aa[b] would be expected to throw a
> range error.

I guess you meant uninitialized.

Fact is, it won't always throw. You might want to test the program with a few
values for a and b.

Timon

Reply via email to