A teacher of mine at NCC course said that a Array cell contains the memory address (pointer) of the next cell. is it true ?

Recommended Answers

All 8 Replies

No. It contains whatever data the array type is.

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.

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.

That’s what I told him. But he told me that I am getting confused :rolleyes: . He said that the array and link list follows the same principle. And each cell contains the next cell address. I told him that they don’t. It is true only for link list not array. Till this it is all right for me. But, then what is the internal mechanism of x ?

Is it something like this ….

int *p;
int x[]={1,2,3,4};


p=&x[0];


//  to get the next index


p++;

>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 ?
x 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. :)

Looking forward to this.

I told him to prove it. But instead he said “do u doubt that I will teach u something wrong? I don’t know what to say after this. So I just left it. I don’t have any wish to fight him. Cause my project mark is on his hand. Thanks for the help any way. I was really confused after what he said about array.

Thanks

>"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]

LOL!

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.

I wish i was there when you did it!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.