answersLogoWhite

0


Best Answer

It's a difference in mentality; some believe 0 is the begin, and is thus the only logical choice, and some think the opposite.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why c and java arrays are start with zero and pascal arrays are start with one?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Why you required zero length array in java?

Yes. We can create an array of zero length in JAVA. Here is an example:class ForFun{int[] nullArray=new int[0];public someMethod(){for(int j=0; j


Why does indexing start with 0 in Java?

Primarily to be compatible with C and C++, which was one of the goals of Java when it was being designed (minimize the learning curve for those familiar with C and C++ to increase adoption). Speaking from a lower-level perspective, arrays are accessed by a pointer and an index. If you call the pointer PTR, and the index IDX, you can access an element in the array by using PTR+IDX. In order to avoid wasting memory, IDX may be zero, since PTR is already allocating that memory to the existence of the array. In languages where IDX starts at 1, PTR[0] stores the number of elements in the array, and can't be directly accessed. Java stores the length of the array elsewhere (in the variable "length"), and so it can start its element allocation at zero.


What do array subscripts always have?

Array subscripts always have a zero-based index. In languages that allow an n-based index, the index is simply offset by n elements, so the compiler subtracts n from the given index to obtain the zero-based index. Arrays are always zero-based because the first element of an array is found zero elements from the start of the array.


Why any number divide by zero bring error in java?

Because by the laws of mathematics, you cannot divide anything by zero. So you will have to adjust your code to allow for that fact.


How can loops be used to process arrays?

Loops can be used to iterate or walk through an array. For example, suppose you have an array already initialized (we'll call it "array"): int target = -1; for (i=0; i < array.length(); i++){ if (array[i] = target){ //do something } } Here, we will walk through an array (note that arrays are zero indexed) using a loop to make sure we hit each element of the array. In our loop, we start at the head (or first element) and iterate over each element.

Related questions

Why you required zero length array in java?

Yes. We can create an array of zero length in JAVA. Here is an example:class ForFun{int[] nullArray=new int[0];public someMethod(){for(int j=0; j


How old was blaise pascal dad when he was born?

Zero.


Why does indexing start with 0 in Java?

Primarily to be compatible with C and C++, which was one of the goals of Java when it was being designed (minimize the learning curve for those familiar with C and C++ to increase adoption). Speaking from a lower-level perspective, arrays are accessed by a pointer and an index. If you call the pointer PTR, and the index IDX, you can access an element in the array by using PTR+IDX. In order to avoid wasting memory, IDX may be zero, since PTR is already allocating that memory to the existence of the array. In languages where IDX starts at 1, PTR[0] stores the number of elements in the array, and can't be directly accessed. Java stores the length of the array elsewhere (in the variable "length"), and so it can start its element allocation at zero.


What is type string in C?

Nothing, zero-terminated char-arrays are used instead of strings.


What is the state of water at zero pascal?

It's still a liquid but it will have a spherical shape.


What do array subscripts always have?

Array subscripts always have a zero-based index. In languages that allow an n-based index, the index is simply offset by n elements, so the compiler subtracts n from the given index to obtain the zero-based index. Arrays are always zero-based because the first element of an array is found zero elements from the start of the array.


Why does array index start with zero in C language?

Because of pointers and that all arrays are really pointers. A pointer something like *pointer can also be written as pointer[0] and *(pointer + 1) can also be written as pointer[1]


What is starting subscripts value for integers arrays?

0. For many (every) languages, for every type of array, the starting subscript is zero.


What is the minimum number of interfaces that a java class can have?

Zero. By default they do not implement any interfaces.


Do line graphs have to start at zero?

no but bar graphs do have to start at zero


Why any number divide by zero bring error in java?

Because by the laws of mathematics, you cannot divide anything by zero. So you will have to adjust your code to allow for that fact.


Winter words that start with z?

zero, as in zero degrees