| | |
Array cell contains the memory address of the next cell ????
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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
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
•
•
•
•
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.
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[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.
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
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
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]
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
![]() |
Similar Threads
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- what is the difference between (ptarray[]) AND &(ptarray[i]) in below example (C++)
- Array a cell (Visual Basic 4 / 5 / 6)
- A puzzl about function (C)
Other Threads in the C Forum
- Previous Thread: Help with a 2D Matrix problem
- Next Thread: Using a variable as an array's index?
Views: 2499 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays bash binarysearch centimeter char convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory drawing dynamic executable fflush file fork frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o inches infiniteloop initialization interest kilometer km lazy linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix meter microsoft motherboard multi mysql open opendocumentformat opensource owf pattern pdf performance pointer pointers posix power problem probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling segmentationfault send shape socketprograming spoonfeeding stack standard strchr string strings structures student suggestions system systemcall test testautomation unix user voidmain() wab win32 win32api windows.h






