No. It contains whatever data the array type is.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
Your teacher is confusing arrays with linked lists. An array is always a contiguous sequence of cells, so there's no need for one cell to "point" to the next. Because the nodes of a linked list are not contiguous in memory, a pointer to the next node is critical.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>He said that the array and link list follows the same principle.
Then he's trying to overgeneralize and comes to the wrong conclusion. Linked lists must point to the next item because there's no other way to find it. Arrays are always contiguous, so moving to the next item in an array of type T is as simple as jumping T bytes forward from the current item. No link is necessary, it's all about offsets, and the offsets can be calculated ad hoc.
>But, then what is the internal mechanism of x[i] ?
x[i] is converted to *(x + i), which eventually becomes *(x + (i * sizeof *x)).
To avoid making your teacher look like a total idiot, it is possible to create linked lists using arrays, where a structure of two items is stored in each cell. One item contains the data and the other contains either the index or the address of the next cell in the list. However, arrays do not work like linked lists internally.
Ask him to prove it. The only way he'll be able to do so is to show you code that doesn't do what he thinks it does, show you code that does what he thinks it does but not what he says it does, or quote another incorrect source. If anything, it should be entertaining to see his reasoning. Please post it so we can all get a good laugh. :)
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>"do u doubt that I will teach u something wrong?"
Hell, yes! Any teacher who's so arrogant as to think he's infallible is not someone you want to be learning from. I recommend finishing out the class (always double checking everything he teaches with a trusted source) and then finding a new instructor. It's obvious from that answer that your teacher thinks he knows everything, and is unwilling to double check himself for accuracy. The good news is that you can probably get away with turning in really crappy code because he doesn't know the language as well as he believes. ;)
[edit]
Please invite him here. I'd love to meet this guy, he sounds like another teacher that I put in his place a couple of years ago.
[/edit]
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401