English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

5 answers

The compiler will always generate internal represenations of arrays that are numbered from 0.

You can do weird tricks so your code reads as if the arrays were numbered from 1

- Ignore the zero element. In all array calculations/references you must ensure you never reference element 0
- Create an array access routine that decrements the index by 1, always use the array access routine to access arrays
- Get the source code for the Gnu C++ compiler and alter it so that all arrays are numbered by 1, and that any reference to array[0] is a fault. Compile it and post it online for everyone who wants natural numbers only.

2007-02-10 03:58:31 · answer #1 · answered by Anonymoose 4 · 0 0

Thats a very intresting question, while I don't belive I can give you a answer that is 100% sure, because of my lack of experence in the real world, I would have to say somewhat. If you use a type of stack data structure where 0 would represent the element you are deleting and 1 as the element in which calculations are done then it would be possible. However I seriously doubt you could just start numbering arrays starting with 1 as the first index instead of 0 in any other case, because while you may not use the data in 0, unless you initaize that index there will always be something there, whatever was stored inside the memory address previously.

In any case, good luck!

2007-02-10 03:50:46 · answer #2 · answered by D 4 · 0 0

An array call is only a pointer to the region of the first aspect in that array. The decision in the sq. brackets denotes the useful offset from that first aspect. hence if the offset is 0 you're searching on the first aspect. also (in C) array[23]==array+23==array[10]+13

2016-12-04 00:06:37 · answer #3 · answered by Anonymous · 0 0

You can use an associative array and start the keys at whatever value you wish. The trouble is you have to manage the incrementing of the keys as you add array elements.

See: http://en.wikipedia.org/wiki/Associative_array#C.2B.2B

2007-02-10 05:08:13 · answer #4 · answered by Joe K 2 · 0 0

yes but it goes against convention so you need to make a note of it for others that may work on your program

2007-02-10 03:50:18 · answer #5 · answered by ? 3 · 0 0

fedest.com, questions and answers