On 2005-02-28 04:18:15 -0500, "ccwork" <> said:
> Hi all,
> I found some people writing code as:
> /****************** sample code ********************/
> int ans;
> ...
> printf("%c\n", " yn"[ans]);
> /***************** sample code end *****************/
>
> The value of variable "ans" will be an index to print ' ', 'y' or
> 'n'. Is this a syntax " yn"[ans] in standard C?
Yes. This might make more sense to you, if you consider that (" yn") is
nothing more than an array of characters. Your sample code is similar
to:
int ans;
const char array[] = " yn";
...
printf("%c\n", array[ans]);
--
Clark S. Cox, III