Array cell contains the memory address of the next cell ????

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2005
Posts: 8
Reputation: hasan2003 is an unknown quantity at this point 
Solved Threads: 0
hasan2003's Avatar
hasan2003 hasan2003 is offline Offline
Newbie Poster

Array cell contains the memory address of the next cell ????

 
0
  #1
Mar 29th, 2005
A teacher of mine at NCC course said that a Array cell contains the memory address (pointer) of the next cell. is it true ?
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,461
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 254
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Array cell contains the memory address of the next cell ????

 
0
  #2
Mar 29th, 2005
No. It contains whatever data the array type is.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,858
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Array cell contains the memory address of the next cell ????

 
0
  #3
Mar 29th, 2005
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.
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 8
Reputation: hasan2003 is an unknown quantity at this point 
Solved Threads: 0
hasan2003's Avatar
hasan2003 hasan2003 is offline Offline
Newbie Poster

Re: Array cell contains the memory address of the next cell ????

 
0
  #4
Mar 29th, 2005
Originally Posted by Narue
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[i] ?

Is it something like this ….

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

p=&x[0];

// to get the next index

p++;
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,858
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Array cell contains the memory address of the next cell ????

 
0
  #5
Mar 29th, 2005
>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.
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 353
Reputation: Asif_NSU is on a distinguished road 
Solved Threads: 3
Asif_NSU's Avatar
Asif_NSU Asif_NSU is offline Offline
Posting Whiz

Re: Array cell contains the memory address of the next cell ????

 
0
  #6
Mar 29th, 2005
Looking forward to this.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 8
Reputation: hasan2003 is an unknown quantity at this point 
Solved Threads: 0
hasan2003's Avatar
hasan2003 hasan2003 is offline Offline
Newbie Poster

Re: Array cell contains the memory address of the next cell ????

 
0
  #7
Mar 30th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,858
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Array cell contains the memory address of the next cell ????

 
0
  #8
Mar 30th, 2005
>"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]
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: Array cell contains the memory address of the next cell ????

 
0
  #9
Mar 30th, 2005
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!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2499 | Replies: 8
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC