--- In [email protected], shamir shakir <dewswo...@...> wrote:
>
> > I have a question here.
> > *    char words[][2][40] = {*
> >
> > *        "dog", "hund",*
> > *        "no", "nein",*
> > *        "year", "jahr",*
> > *        "child", "kind",*
> > *        "i", "ich",*
> > *        "drive", "fahren",*
> > *        "house", "haus",*
> > *        "to", "zu",*
> > *        "", ""*
> > *        };
> > can be written as
> > **    char words[][2][40] = {*
> > *        "dog", "hund",**"no", "nein",**"year", "jahr",**"child", "kind",*
> > *"i", "ich",**"drive", "fahren",**"house", "haus",**"to", "zu",**"", ""**
> > };*
> >
> > If so, how the i'th pair can be calculated by the compiller ?

I think this is a new question, although I'm not sure I understand it.

char words[][2][40] = {
  "a0", "a1",
  "b0", "b1",
  "c0", "c1",
  "d0", "d1"
};

is exactly the same as:

char words[][2][40] = {"a0", "a1", "b0", "b1", "c0", "c1", "d0", "d1"};

or, the 'proper' way:

char words[][2][40] = {
  {"a0", "a1"},
  {"b0", "b1"},
  {"c0", "c1"},
  {"d0", "d1"}
};

which could be written as:

char words[][2][40] = {{"a0", "a1"}, {"b0", "b1"}, {"c0", "c1"},{"d0", "d1"}};

Note that although each string is only 2 characters long, or 3 if you include 
the '\0' string terminator character which is added by the compiler, the 
compiler still allocates space for 40 characters for each string.

Hence the start of the i'th pair of strings, words[i][0] (or &words[i][0][0]) 
is at address:

  words + i * 2 * 40

Does that answer your question?

Reply via email to