Re: newbie...please help




Bart wrote:
> cj wrote:
>
> > Which animal will be replaced with "fly" in the following code
> > fragment?
> > char animals [ ] [3][6] = {
> > "cow","pig","dog","rat","bat","hen","eel","ant","cat","ox","owl","yak","ram­","bee","doe"}
> >
> > strcpy(animals [2] [1] , "fly");
>
> I don't get this either. A 3D array is declared then initialised with
> 2D content. Am I missing something? It works better without the [3] and
> the [1].
>
> Bart

Because a string is in itself an array, a 2D array of strings would
actually be a 3D array.
That's why you shouldn't learn C without programming experience: It's
hellishly complicated.

Ex. animals[0][0][0] == 'c', whereas animals [0][0] = "cow" and animals
[0] = [the address in memory of "cow"]


In the textbook of the original poster, this information should be
under "arrays", "multidimensional arrays", or "strings". The index
should have all three of those.

.



Relevant Pages