- How do you access the values within an array?
Arrays contain a number of elements, depending on the size you gave it during variable declaration. Each element is assigned a number from 0 to the number of elements-1. To assign or retrieve the value of a particular element, refer to the element number. For example: if you have a declaration that says “intscores;”, then you have 5 accessible elements, namely: scores, scores, scores, scores and scores.
- What is the advantage of an array over individual variables?
When storing multiple related data, it is a good idea to use arrays. This is because arrays are named using only 1 word followed by an element number. For example: to store the 10 test results of 1 student, one can use 10 different variable names (grade1, grade2, grade3… grade10). With arrays, only 1 name is used, the rest are accessible through the index name (grade, grade, grade… grade).
- Difference between an array of pointers and a pointer to an array?
Array of pointers:
1- Declaration is: data_type *array_name[size];
2-Size represents the row size.
3- The space for columns may be dynamically
Pointers to an array:
1-Declaration is data_type ( *array_name)[size];
2-Size represents the column size.
- Dis-Advantage of array?
Fixed Size: Whatever size, we define at the time of declaration of array, we cannot change their size, if you need more memory in that time you cannot increase memory size, and if you need less memory in that case also wastage of memory.
- Two-dimentional array?
In 2-dimentional elements are arranged in row and column format.
When we are working with 2-dimentional array we require referring 2-subscript operator which indicates the row and column sizes.
The main memory of 2-dimentional array is rows and sub-memory is columns.
On 2-dimentional array when we are referring one-subscript operator then if gives row address, 2-subscript operator will gives element.