answersLogoWhite

0

Yes, that's the idea of an array.

Yes, that's the idea of an array.

Yes, that's the idea of an array.

Yes, that's the idea of an array.

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering

Application of array in data structure?

That rather depends on the underlying type. For any given type T, an array of type T is user-defined if T is user-defined, otherwise it is built-in. For example: #include<string> // required to use std::string std::string s[42]; // user-defined array int i[42]; // built-in array Here, s is a user-defined array because std::string is a user-defined type, whereas i is a built-in array because int is a built-in type.


What is the difference between a string and an array?

Nothing whatsoever. A string is simply an array of type char. In some programming languages, such as C, a string is an array of char (or short), terminated with a null \0. An array is just a fixed size of collection, a container to hold things/objects. If all the elements in the container are characters (of char), then we may call it a string, sometimes a byte array (because each character can be represented as a byte). An array of 7 different days, it maybe a WEEK, or just the birthdays of 7 dwarfs. Then they are nothing to do with strings. A data item (or variable) is described as a "string" type when it contains some number of characters. Those characters can usually be anything in the system's accepted list of codes. Most systems use ASCII, so a string can include the letters a-z, A-Z, numbers 0-9, and special characters like ~!@#$%^&*()_+-=[]\{}|:";'<>?,/. A string is treated as a single object, although most programming languages have methods to break strings apart (called sub-stringing). In the Perl language, strings are named $something. An array is a collection of individual data items, sort of like a list. Each element in an array can be referred to in a program by its position in the list. In the Perl language, an array would be named @SOMETHING. The first element in the array would be named $SOMETHING[0], the second $SOMETHING[1], and so on. Each element can be a string, or some other data type. Other data types would be integers (positive or negative whole numbers), floating point (decimal numbers like 3.14159 or 2398.41; it can be more complicated than this, but that's another story), and a few more exotic types. In the C programming language a string is actually the same as an array of characters. The last character in a C string is a zero byte which indicates the end of the string.


Why arrays are using?

1. An array cuts down on the number of variables that need to be declared.For example, if you wanted to store the numbers 1 to 10 without using an array you would literally have to declare ten separate variables.Dim int1 as Integer = 1Dim int2 as Integer = 2Dim int3 as Integer = 3Dim int4 as Integer = 4Dim int5 as Integer = 5Dim int6 as Integer = 6Dim int7 as Integer = 7Dim int8 as Integer = 8Dim int9 as Integer = 9Dim int10 as Integer = 10Which is monstrously difficult to read and use further along in your code. A better way of doing it would be to use one variable; an integer array.Dim intArray() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}Using this example you use the same variable throughout your code and access different parts of it as follows;Dim intArray() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}Dim intTemp as IntegerMsgBox(intArray(0))MsgBox(intArray(4))This example displays two textboxes which will display the number 1 and 5 to the user (Note that array starts at zero)2. An array can be used in itterative procedures such as a For... Next loop.For example if we use the previous example of an integer array containing numbers 1 through 10, and with this array we want to display every number to the user.Without an array this is an almighty block of code with a minimum of 20 lines, 10 declaring each variable and 10 outputting it to the user. With an array this can be reduced to four lines.Dim intArray() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}For i = 0 to intArray.LengthMsgBox(intArray(i))NextThe importance of this is that in our example we only have ten numbers stored, in the real world you could have hundreds. Declaring hundreds of variables and messing around with them will take up memory, obfuscate the code immensely and make it virtually unchangeable.With the above example that array could be any length and contain a thousand variables and still function the same.3. An array can be declared as a variable length.Whilst it's all well good saying we have an example array containing numbers 1 through 10, it is unlikely to ever be that simple; we will always want to store an unknown amount of data at runtime.Just declaring variables in the code wouldn't work for this because they would need to be hardcoded.In this example we will pretend a form has been made with a listview containing a hundred items, when a user clicks a button we want to store everything they selected in the listview. (If you don't know what a listview is I would ask that question as well)Dim intVarArray(ListView1.SelectedItems.Count - 1) as IntegerFor i = 0 to ListView1.SelectedItems.Count - 1intVarArray(i) = ListView1.SelectedItems(i).ToString NextTo do this using nothing but variables would be near impossible as you wouldn't know how many items the user would select, as such you would have to declare a hundred variables and write hundreds of lines of code to do something that can be covered in four lines.4. An array can be resized on the fly, either destroying or preserving existing data.In the above example we created an array of variable length and then stored some data from a made up listview control, but it's possible when working in the real world we may need to add things to that variable.We can Redim an array to change its length.Dim intArray(9) as IntegerRedim intArray(14)This declares a variable of an array of integers, sets the length to 10 and then redefines that array as an array of length 15. This will completely remake the variable destroying any data held within it.Dim intArray(9) as Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}Redim Preserve intArray(14)intArray(10) = 11intArray(11) = 12intArray(12) = 13intArray(13) = 14intArray(14) = 15This declares a variable of length 10 and stores the number 1 to 10 inside it, it then redefines the variable as length 15 but preserves the data within it (It then adds the number 11 to 15 to that variable).5. An array can have multiple dimensions.Dim intArray(, ) as String = {{"White", "Rabbit"}, {"Brown", "Bear"}, {"Blue", "Water"}}This declares something more unique than any other type of single variable, a multidimensional array, and stores some data within it.--Ac532 Answer:Arrays can be disposed by using the .Dispose which means all allocated memory toward using the array will be lost meaning that your program will run faster.


How arrays are used in synon?

Synon array processing is totally intuitive for any synon user. You do not need to open a manual. If you can use a file, you can use an array. The main difference is that there are only 4 function types: CRTOBJ, CHGOBJ, DLTOBJ, RTVOBJ, and only 1 "ACP" (set of Key fields)The array processing really behaves more like an indexed file than an array. The file portion (Records) is a multiple occurrence data structure and the index portion is an array. The data structure contains the fields as defined in the *ARRAY file. The array(Index) is the fields defined as the Key concatenated with the occurrence# of the data structure. When you create an element in the array (a record in the file), the program takes the next available occurrence of the data structure and loads the fields. The program also creates the Index element by concatenating the key fields with the occurrence# of the newly added data structure. The program then does a Sort Array to sequence the Index so that the records may be accessed in key sequence. Any time a record is deleted, the Index element is blanked out and the Index is Sorted (Sort Array). This is a very clean solution and the performance is surprisingly good considering that the array is sorted after each add or delete.When accessing the data, a LOKUP is performed on the array using the key value with blanks instead of the occurrence# and looking for GT in the array. This allows processing of partial keys as positioners or restrictors. The program then reads the data structure for the occurrence# taken from the array element to get the data(fields). For the next occurrence, it is not necessary to do another LOKUP (which is slow) because the array is sorted. The program only has to read the next element in the array and continue the processing as long as the partial key matches the key in the array. From the point of view of the Synon user, this processing is identical to a file RTVOBJ.Synon loads the array from the bottom (an RPG technique to improve performance in large arrays) because the LOKUP command may be given a starting position, but cannot be stopped until every element is checked when no match is found. By loading the array backwards from the bottom and counting the elements, the search may be started at the last element loaded and only elements which contain data are read.IF No Match is FoundAn array is defined for 1000 elements.Only 10 elements are loaded.These are loaded to occurrences 991 thru 1000.When the LOKUP is performed, it starts at 991 and only 10 compares are made.** If the array is loaded from the top, 1000 compares are performed.


What is the difference between passing an array and passing single value data to a function?

Passing a single value to a function is often just a simple integer. But passing an array, character string or other data structure is typically "pass by reference", or in other words, the calling statement will 'point to' the place in memory where the data structure resides.When a function is called using a pointer to a data structure, both the calling environment and the called function are referencing the same data; any changes made to the data in the structure by the function will have changed the data that the original calling environment sees.However, when a value is passed to a function, the function creates it's own copy of the value, and can change it in any way without changing the original value.

Related Questions

Application of array in data structure?

That rather depends on the underlying type. For any given type T, an array of type T is user-defined if T is user-defined, otherwise it is built-in. For example: #include<string> // required to use std::string std::string s[42]; // user-defined array int i[42]; // built-in array Here, s is a user-defined array because std::string is a user-defined type, whereas i is a built-in array because int is a built-in type.


Can a prime number be made into an array?

Yes, a unit array.


What are the differences between structures and arrays?

Arrays are collections of repeated data items. Structures are complex data items made up of other data items, including, potentially, other structures and arrays. You can, of course, also have arrays of structures. Array items can be accessed by using its subscript whereas structure items can be accessed using its dot or "arrow" operator in C, C++, C#, Java, and JavaScript.


What kinds of items are made of brown leather?

Leather is a durable flexible material which can be used to produce many items. These can range from clothing, such as jackets, to an array of furniture possibilities.


How does the number of factors determine the number of different rectangular arrays that can be made for given number?

Each factor pair is an array.


How can perfect numbers be found using PHP?

It will be a loop if you want to try each number in turn. Make sure you make some way to get out of the loop, or it will run forever.First, you will have to find all factors of the number and store them in an array. divide the index number by every number between it and 1. There won't be any decimals if it is a factor.Note: the divisor and the answer will both be factors.Then, add up all of the items in that array and compare it to the index number. If there is a match, then you've found a perfect number!If you made it so the index number is part of the array, then you'll have to remove it by halving the added array's result.The first four perfect numbers are 6, 28, 496 and 8128.


How many comparisons are typically made in a binary search algorithm when searching for a specific element in a sorted array?

In a binary search algorithm, typically log(n) comparisons are made when searching for a specific element in a sorted array, where n is the number of elements in the array.


What is the difference between a numericial array and an associative array?

A numericial array is an array with keys made up of only integers. An associative array is an array with keys made up of anything that is not an integer. In some languages, it is possible to mix integer keys and non-integer keys into a mixed array.


What is the difference between a string and an array?

Nothing whatsoever. A string is simply an array of type char. In some programming languages, such as C, a string is an array of char (or short), terminated with a null \0. An array is just a fixed size of collection, a container to hold things/objects. If all the elements in the container are characters (of char), then we may call it a string, sometimes a byte array (because each character can be represented as a byte). An array of 7 different days, it maybe a WEEK, or just the birthdays of 7 dwarfs. Then they are nothing to do with strings. A data item (or variable) is described as a "string" type when it contains some number of characters. Those characters can usually be anything in the system's accepted list of codes. Most systems use ASCII, so a string can include the letters a-z, A-Z, numbers 0-9, and special characters like ~!@#$%^&*()_+-=[]\{}|:";'<>?,/. A string is treated as a single object, although most programming languages have methods to break strings apart (called sub-stringing). In the Perl language, strings are named $something. An array is a collection of individual data items, sort of like a list. Each element in an array can be referred to in a program by its position in the list. In the Perl language, an array would be named @SOMETHING. The first element in the array would be named $SOMETHING[0], the second $SOMETHING[1], and so on. Each element can be a string, or some other data type. Other data types would be integers (positive or negative whole numbers), floating point (decimal numbers like 3.14159 or 2398.41; it can be more complicated than this, but that's another story), and a few more exotic types. In the C programming language a string is actually the same as an array of characters. The last character in a C string is a zero byte which indicates the end of the string.


How many combinations can be made from 10 different items?

There is only one combination of ten items out of ten. For this question to have a non-trivial answer, either the ten items need to be selected from a larger number of items or a smaller number of items need to be selected from the ten items.


Why arrays are using?

1. An array cuts down on the number of variables that need to be declared.For example, if you wanted to store the numbers 1 to 10 without using an array you would literally have to declare ten separate variables.Dim int1 as Integer = 1Dim int2 as Integer = 2Dim int3 as Integer = 3Dim int4 as Integer = 4Dim int5 as Integer = 5Dim int6 as Integer = 6Dim int7 as Integer = 7Dim int8 as Integer = 8Dim int9 as Integer = 9Dim int10 as Integer = 10Which is monstrously difficult to read and use further along in your code. A better way of doing it would be to use one variable; an integer array.Dim intArray() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}Using this example you use the same variable throughout your code and access different parts of it as follows;Dim intArray() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}Dim intTemp as IntegerMsgBox(intArray(0))MsgBox(intArray(4))This example displays two textboxes which will display the number 1 and 5 to the user (Note that array starts at zero)2. An array can be used in itterative procedures such as a For... Next loop.For example if we use the previous example of an integer array containing numbers 1 through 10, and with this array we want to display every number to the user.Without an array this is an almighty block of code with a minimum of 20 lines, 10 declaring each variable and 10 outputting it to the user. With an array this can be reduced to four lines.Dim intArray() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}For i = 0 to intArray.LengthMsgBox(intArray(i))NextThe importance of this is that in our example we only have ten numbers stored, in the real world you could have hundreds. Declaring hundreds of variables and messing around with them will take up memory, obfuscate the code immensely and make it virtually unchangeable.With the above example that array could be any length and contain a thousand variables and still function the same.3. An array can be declared as a variable length.Whilst it's all well good saying we have an example array containing numbers 1 through 10, it is unlikely to ever be that simple; we will always want to store an unknown amount of data at runtime.Just declaring variables in the code wouldn't work for this because they would need to be hardcoded.In this example we will pretend a form has been made with a listview containing a hundred items, when a user clicks a button we want to store everything they selected in the listview. (If you don't know what a listview is I would ask that question as well)Dim intVarArray(ListView1.SelectedItems.Count - 1) as IntegerFor i = 0 to ListView1.SelectedItems.Count - 1intVarArray(i) = ListView1.SelectedItems(i).ToString NextTo do this using nothing but variables would be near impossible as you wouldn't know how many items the user would select, as such you would have to declare a hundred variables and write hundreds of lines of code to do something that can be covered in four lines.4. An array can be resized on the fly, either destroying or preserving existing data.In the above example we created an array of variable length and then stored some data from a made up listview control, but it's possible when working in the real world we may need to add things to that variable.We can Redim an array to change its length.Dim intArray(9) as IntegerRedim intArray(14)This declares a variable of an array of integers, sets the length to 10 and then redefines that array as an array of length 15. This will completely remake the variable destroying any data held within it.Dim intArray(9) as Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}Redim Preserve intArray(14)intArray(10) = 11intArray(11) = 12intArray(12) = 13intArray(13) = 14intArray(14) = 15This declares a variable of length 10 and stores the number 1 to 10 inside it, it then redefines the variable as length 15 but preserves the data within it (It then adds the number 11 to 15 to that variable).5. An array can have multiple dimensions.Dim intArray(, ) as String = {{"White", "Rabbit"}, {"Brown", "Bear"}, {"Blue", "Water"}}This declares something more unique than any other type of single variable, a multidimensional array, and stores some data within it.--Ac532 Answer:Arrays can be disposed by using the .Dispose which means all allocated memory toward using the array will be lost meaning that your program will run faster.


How arrays are used in synon?

Synon array processing is totally intuitive for any synon user. You do not need to open a manual. If you can use a file, you can use an array. The main difference is that there are only 4 function types: CRTOBJ, CHGOBJ, DLTOBJ, RTVOBJ, and only 1 "ACP" (set of Key fields)The array processing really behaves more like an indexed file than an array. The file portion (Records) is a multiple occurrence data structure and the index portion is an array. The data structure contains the fields as defined in the *ARRAY file. The array(Index) is the fields defined as the Key concatenated with the occurrence# of the data structure. When you create an element in the array (a record in the file), the program takes the next available occurrence of the data structure and loads the fields. The program also creates the Index element by concatenating the key fields with the occurrence# of the newly added data structure. The program then does a Sort Array to sequence the Index so that the records may be accessed in key sequence. Any time a record is deleted, the Index element is blanked out and the Index is Sorted (Sort Array). This is a very clean solution and the performance is surprisingly good considering that the array is sorted after each add or delete.When accessing the data, a LOKUP is performed on the array using the key value with blanks instead of the occurrence# and looking for GT in the array. This allows processing of partial keys as positioners or restrictors. The program then reads the data structure for the occurrence# taken from the array element to get the data(fields). For the next occurrence, it is not necessary to do another LOKUP (which is slow) because the array is sorted. The program only has to read the next element in the array and continue the processing as long as the partial key matches the key in the array. From the point of view of the Synon user, this processing is identical to a file RTVOBJ.Synon loads the array from the bottom (an RPG technique to improve performance in large arrays) because the LOKUP command may be given a starting position, but cannot be stopped until every element is checked when no match is found. By loading the array backwards from the bottom and counting the elements, the search may be started at the last element loaded and only elements which contain data are read.IF No Match is FoundAn array is defined for 1000 elements.Only 10 elements are loaded.These are loaded to occurrences 991 thru 1000.When the LOKUP is performed, it starts at 991 and only 10 compares are made.** If the array is loaded from the top, 1000 compares are performed.