Is the index or subscript in an array a positive integer or a real number? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

Is the index or subscript in an array a positive integer or a real number?

I do know that array index starts from 0 so my answer is it that it should be a real number since 0 is not positive.

23rd Apr 2020, 4:47 PM
Rabbu Fatima
Rabbu Fatima - avatar
8 Answers
+ 3
Rabbu Fatima Index of array in C, is must be a whole number (positive numbers, along with zero). But not real number. Negetive index used in python not in C. You can declare array size with a whole number. While accessing you should access with in the range of the size. Exceeding the range sholud generate error but c compiler not that much strict but return a garbage value.
23rd Apr 2020, 6:02 PM
Jayakrishna 🇮🇳
+ 2
Rabbu Fatima Specify a language in thread tags, the scope of the question is unclear without a specific language tagged. Which can lead to misunderstanding or unexpected answer.
23rd Apr 2020, 5:06 PM
Ipang
0
It could be positive/negative/zero. U already know 0 and positive. Negative is used for backward indexing. -1 is last element, -2 second last
23rd Apr 2020, 4:58 PM
Prabhakar Rai
Prabhakar Rai - avatar
0
The options are positive integer, real number, positive or negative integer
23rd Apr 2020, 6:25 PM
Rabbu Fatima
Rabbu Fatima - avatar
0
Rabbu Fatima In declaration of array, size must be positive. Int a[0]; is no use... int a[-2] is invalid.. Error int a[1.2] is invalid.. Error. But you can access a[0]. You can write Negetive index while retrieving but it is no use and invalid, return garbage value.a[-1], a[-2].. Otherthan defined values , in array return garbage values.. So it will not generate error for Negetive index but no use of that any where. So for size, it must be positive, for indexing you may write positive or negative including zero but other than values defined withing the range 0 to size-1 will return garbage values.. So from where you found question.. idk, from that perticularly streesing of Negetive index posibilty in c is, i think has no meaning.. So for size must be positive. For retrieving you can index -ve also but no use.
23rd Apr 2020, 7:39 PM
Jayakrishna 🇮🇳
0
This question was on my online test today. Thank you for the explanation.
23rd Apr 2020, 7:42 PM
Rabbu Fatima
Rabbu Fatima - avatar
0
Your welcome..
23rd Apr 2020, 7:52 PM
Jayakrishna 🇮🇳
0
zero is both positive and negative (in computer context at least, in math context zero is neither negative nor positive) and +0 == -0 (but most of scripting/programming language internally could store both, even if it's an hidden behavior). indexes are used to get/set the i-th item of the array (list in python) so should be integer... but as interger are subset of real (float) numbers, you could use an integer stored as a real number (ie: 42.0 will work as 42). And real number not integer have no sense as indexes values (think of the array/list as a desk with drawers: that no sense to talk of the 4.2-th drawer ^^) so, unless you're not in a python context, index must be positive integers (including 0 ;))...
25th Apr 2020, 5:57 AM
visph
visph - avatar