answersLogoWhite

0


Best Answer

length

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: This array field holds the number of elements that the array has?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

In Computer programming Why is it considered good programming practice to define the number of array items as a constant before declaring the array?

In computer programming, (1) When a number is needed several times in a program, it is good practice to give that number a name. (2) When a name refers to a number that will never change during a run of a program, it is good practice to declare it as a constant before using it. In most programming languages, we do not define the number of array items as a constant. In many programming languages, it is easy to add items to an array, and an array keeps track of the number of items it holds, which a program can access using something like "array.length" or "array.shape". However, in C and C++ programming, the programmer must define the size of the array at the time it is defined, and the array does not keep track of the number of items it contains. To not define your array would leave the program open to unchecked growth. "Capping" the array with an upper value ensures that, if something goes wrong, you will not crash the application or system. Also, capping the array will make debugging potentially easier. Capping requires using that number in several places, and so (1) tells us it is good practice to give that number a name. Since it is not possible(*) to change the size of an array in C or C++, the number that holds the number of items in the array will never change, and so (2) tells us it is good practice to declare it as a constant. (*) There are a few tricks one can do with malloc() and realloc() that have the same effect as resizing an array, although technically all those tricks merely create a new fixed-size array.


What is the container object that holds a fixed number of values of single type?

There are multiple answers to this question, but the most basic one common to both Java and C is the array. An array is a simple structure that you initialize to a certain size and fill with data. Think of an array as a sort of list, where each element in the list is numbered starting from zero up to the list size minus one (or the array is zero-based, as it's also called). In Java: // 10 is the number of elements the array can hold int[] myIntArray = new int[10]; myIntArray[0] = 2; // The first element in the array myIntArray[9] = 4; // The last element in the array Referencing myIntArray[10] or higher will cause a runtime error in Java, which may stop your program. In C: // 10 is the number of elements the array can hold int myIntArray[10]; myIntArray[0] = 2; // The first element in the array myIntArray[9] = 4; // The last element in the array Referencing myIntArray[10] or higher results in a buffer overflow in C (and C++). Note that in C, this won't throw errors like they do in Java, and this can and very likely will cause your program to have random bugs and possibly even crash from a segmentation fault, so be a bit more careful about using arrays in C.


What is javascript array object?

An object in JavaScript is anything that holds information. Arrays, strings, numbers and booleans are all objects. You can then use methods and functions to manipulate those objects. If you want to know more about objects, see the related links.


What is a complex data structure?

A complex data structure is the kind of structure that has two arrays. One array hols the real part of the complex data and the other array holds the imaginary part.


What is the importance of using an array in C plus plus programming?

When there is a need of storing a list of same type of large no. of data in linear manner,it is ridiculous to use large no. of different variables.It is more complex also.So in c and c++ array is used.If the ans helps you,plz increase the trust point.

Related questions

What are array of string pointers?

An array of pointers to string would contain, per array position, a number dictating which memory address holds the string data. For example, position [0] in an array would contain a memory address. This memory address can be de-referenced to obtain the actual information held within that memory address.


In Computer programming Why is it considered good programming practice to define the number of array items as a constant before declaring the array?

In computer programming, (1) When a number is needed several times in a program, it is good practice to give that number a name. (2) When a name refers to a number that will never change during a run of a program, it is good practice to declare it as a constant before using it. In most programming languages, we do not define the number of array items as a constant. In many programming languages, it is easy to add items to an array, and an array keeps track of the number of items it holds, which a program can access using something like "array.length" or "array.shape". However, in C and C++ programming, the programmer must define the size of the array at the time it is defined, and the array does not keep track of the number of items it contains. To not define your array would leave the program open to unchecked growth. "Capping" the array with an upper value ensures that, if something goes wrong, you will not crash the application or system. Also, capping the array will make debugging potentially easier. Capping requires using that number in several places, and so (1) tells us it is good practice to give that number a name. Since it is not possible(*) to change the size of an array in C or C++, the number that holds the number of items in the array will never change, and so (2) tells us it is good practice to declare it as a constant. (*) There are a few tricks one can do with malloc() and realloc() that have the same effect as resizing an array, although technically all those tricks merely create a new fixed-size array.


What does PGA mean in computing?

PGA Pin Grid Array is the socket that holds the CPU, there is also the LGA/ land grid array


Why should we preserve the rainforest of Panama?

Because it holds an array of endangered amphibians


What is the container object that holds a fixed number of values of single type?

There are multiple answers to this question, but the most basic one common to both Java and C is the array. An array is a simple structure that you initialize to a certain size and fill with data. Think of an array as a sort of list, where each element in the list is numbered starting from zero up to the list size minus one (or the array is zero-based, as it's also called). In Java: // 10 is the number of elements the array can hold int[] myIntArray = new int[10]; myIntArray[0] = 2; // The first element in the array myIntArray[9] = 4; // The last element in the array Referencing myIntArray[10] or higher will cause a runtime error in Java, which may stop your program. In C: // 10 is the number of elements the array can hold int myIntArray[10]; myIntArray[0] = 2; // The first element in the array myIntArray[9] = 4; // The last element in the array Referencing myIntArray[10] or higher results in a buffer overflow in C (and C++). Note that in C, this won't throw errors like they do in Java, and this can and very likely will cause your program to have random bugs and possibly even crash from a segmentation fault, so be a bit more careful about using arrays in C.


How 3d arrays are represented in memory?

All multi-dimensional arrays are represented as arrays of arrays. That is, each element of the array is itself an array. Thus a two-dimensional array can be thought of as being a one-dimensional array where every element is a one-dimensional array. A three-dimensional array is therefore a one-dimensional array of two-dimensional arrays. And so on. The actual memory layout of a multi-dimensional array is no different to that of a one-dimensional array of the same size: int a[12]; int b[3][4]; Assuming a 4-byte int, the amount of memory allocated to a is 12 x 4 = 48 bytes. The array b is essentially an array where each element holds an array of 4 integers, thus each element is 16 bytes in length. Given there are 3 such elements in total, the total size of b is 3 x 16 = 48 bytes, the same as was allocated to a. Although the allocations are exactly the same in terms of size, the layouts differ. The array a is an array of twelve 4-byte elements (of type int) whereas array b is an array of three 16-byte elements, each of which is itself an array of four 4-byte elements (of type int). This changes the way we refer to the individual elements of the array. Every element in an array is referred to by its offset address from the start of the array. This is determined by multiplying its zero-based index by the element size. In the case of a, every element is 4-bytes in length, thus element a[2] refers to the element that is offset 2 x 4 = 8 bytes from the start of the array. But in the case of b, however, b[2] would refer to the 16-byte element that is offset 2 x 16 = 32 bytes from the start of the array. Given that we're actually referring to an element which is itself a 4-element array, we must use a second subscript to refer to the elements of that array. Thus b[2][3] would refer to the integer that is offset 3 x 4 bytes from the start of the array referred to by b[2]. Extending this idea into three-dimensions is simply a matter of taking a third subscript into account.


What is javascript array object?

An object in JavaScript is anything that holds information. Arrays, strings, numbers and booleans are all objects. You can then use methods and functions to manipulate those objects. If you want to know more about objects, see the related links.


What is a key Field?

A field in a part or record that holds the value of a key to that record.


What is key field?

A field in a part or record that holds the value of a key to that record.


What is a complex data structure?

A complex data structure is the kind of structure that has two arrays. One array hols the real part of the complex data and the other array holds the imaginary part.


What is the importance of using an array in C plus plus programming?

When there is a need of storing a list of same type of large no. of data in linear manner,it is ridiculous to use large no. of different variables.It is more complex also.So in c and c++ array is used.If the ans helps you,plz increase the trust point.


How many people does lp field hold?

LP field holds almost 70,000 people.