answersLogoWhite

0


Best Answer

A one-dimensional array is an array where each element in the array points to a specific value of the type specified by the array (all values must be of the same type). For example, we can store integer values in an integer array, character values in a character array and strings in a string array.

Multi-dimensional arrays are implemented as one-dimensional arrays where every element is itself a one-dimensional array, for as many dimensions as required. The overall size of any array (in elements) is the product of all its dimensions, thus a two-dimensional array of 4x5 elements has 20 elements in total, divided into 4 arrays of 5 elements each. However, because all the elements are allocate contiguously, any multi-dimensional array can be treated as if it were one-dimensional. Note that every element of an array must be exactly the same length, even when that element is another array.

The most common type of array we use is a pointer array (an array of pointer elements). Given that a non-null pointer does not store any size information (the number of elements being referred to), we typically use null-terminated pointer arrays, where a null pointer denotes the end of the array being referred to. This makes it possible to implement "jagged" or "irregular" multi-dimensional arrays, where each dimension can be a different length. An array of variable-length strings is an example of a jagged array, such that each element points to a null-terminated character array.

User Avatar

Wiki User

6y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

Arrays of several dimension can be used in C. A char[] array is one, int[4] another.

One suggested online reference is:

http://computer.howstuffworks.com/c.htm/printable

Navigate down to the section "Arrays"

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

Here is a statical array:

int arr[50]; /* 50 integers in the array */

/* setting some values */

arr[0] = 1;

arr[1] = 2;

...

int matrix[10][10]; /* we have a matrix 10 x 10 of integers */

/* setting some values */

matrix[0][0] = 1;

matrix[1][1] = 2;

matrix[3][5] = 3;

...

You can initialize array at the time of creation:

int arr[3] = { 0, 1, 3 };

/* or could do like this */

int arr[] = { 0, 1, 2, 3, 4, 5 };

int matrix[2][4] = { 0, 0, 0, 01, 1, 1, 1};

/* is the same as: */

int matrix[2][4] = { { 0, 0, 0, 0 }, { 1, 1, 1, 1} };

C Arrays are no limited only to one and two dimensional arrays, you can define N-dimensional arrays too.

int cube[3][3][3]; /* here we have a cube 3 x 3 x 3*/

There are dynamic arrays too, but that requires knowledge of memory management and pointers. There are some links that will explain arrays in C more detailed.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

A single dimension array is an array with one dimension. It is a collection in memory of one or more elements of the same type.

int array[100];

declares an array of int's of size 100 elements. The elements are referenced as array[0], the first one, through array[99], the last one.

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

An array is an aggregate of two or more un-named values of the same type allocated within contiguous memory. All arrays can really be considered one-dimensional because even a two-dimensional array is really just an array of arrays. An array of strings is an example of a two-dimensional array, but is usually easier to imagine as being a one dimensional array of strings rather than as being a one-dimensional array of character arrays. While its less of a problem imagining a two dimensional array as being a table of values arranged in rows and columns and a three dimensional array as being an array of tables (or a "cuboid"), it's usually easier to think of four or more dimensions in simple terms because it is hard to imagine more than 3 dimensions within a 3 dimensional world. For instance, a four-dimensional array might be easier to imagine as being an array of cubes or as a table of tables. If you treat each dimension as if it were one-dimensional, it becomes that much easier to visualise.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

The term "1D array" refers to the number of dimensions in an array. The following illustrates this using [] as each cell in the array:

[0] [1] [2] [3] [4]

The first cell is index "0" (zero) under C; then indices 1, 2, 3 and 4 follow it. There are five total indices in the array, so the size of the array is 5. Each cell can contain values other than the ones listed:

[55] [-647] [2] [42] [1923874]

Arrays under C can consist of many dimensions, although more dimensions tend to complicate code quite a bit. See the related link below for more information on C arrays.

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

Arrays can be used wherever you require a simple data sequence where every element is of the same type.

The advantage of an array is that elements are aligned in contiguous memory thus it is trivial to access any element in the array using pointer arithmetic or using the array suffix operator. This makes it possible to achieve constant time random access and thus traverse arrays in a non-linear manner. For instance, we can represent a sorted sequence most efficiently using a balanced binary tree within an array, where the first element represents the root (the mid-value in the sequence), the next two elements its children, and the next four elements its grandchildren, and so on.

The disadvantage of an array is that it is not suitable for insertions or extractions except at the end of the array. This is because elements must be physically moved in memory in order to make a gap for an insertion (or to remove a gap after an extraction) whereas inserting only at the end is simply a case of re-allocating the array to cater for the new element (for optimal performance, we never reduce the size of an array during an extraction -- we simply keep track of the number of unused elements at the end of the array).

Even so, re-allocating an array may result in the entire array being moved to new memory if there is insufficient contiguous memory to expand into. This can be a costly operation because every element must then be copied to the new memory. However, we can improve performance simply by allocating more elements than we need. That is, each time we need to re-allocate, we increase the allocation size by 200% (doubling its size). If memory is a concern, the optimal increase is around 160%.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

Quite simply: add another set of brackets to the declaration.

int[] a; // array of ints

int[][] b; // array of array of ints (two-dimensional array)

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

Usable. It can represent a string but remember that in c language strings have to be zero terminated.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Example: int x[32];

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you create a two dimentional array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Declaration of two dimentional array in functions?

Possible. void foo (void) { int array [10][20]; ... }


How do you initialise a two dimentional array?

C provides rectangular multidimensional arrays. In C, a two-dimensional array is really a one-dimensional array, each of whose elements is an array. An array is initialized by a list of initializations in braces; each row of a two-dimensional array is initialized by a corresponding sub-list. Example of two dimensional array initialization: char array_example[2][4] = { {11, 12, 13, 14}, {21, 22, 23, 24} };


What does a 2 dimensional array do?

A two dimensional array is a one-dimensional array of one-dimensional arrays. That is, just as we can have an array of integers, we can also have an array of integer arrays. This idea can be extended such that we can have an array of two-dimensional arrays (a three-dimensional array), and so on. We typically use a two-dimensional array to represent a table of rows and columns, where each row is a one-dimensional array.


Could array may have elements that are numbers and strings?

In Java:Not as primitives; but I believe you could create an array of Objects, and then initialize the elemnets as subtypes of the Object class, i.e., any class. I don't think this would be very practical (in Java); if (for example) you need to store information about people's names with their ages, create a class called "Person" that has those two attributes, then create an array of Persons.In Java:Not as primitives; but I believe you could create an array of Objects, and then initialize the elemnets as subtypes of the Object class, i.e., any class. I don't think this would be very practical (in Java); if (for example) you need to store information about people's names with their ages, create a class called "Person" that has those two attributes, then create an array of Persons.In Java:Not as primitives; but I believe you could create an array of Objects, and then initialize the elemnets as subtypes of the Object class, i.e., any class. I don't think this would be very practical (in Java); if (for example) you need to store information about people's names with their ages, create a class called "Person" that has those two attributes, then create an array of Persons.In Java:Not as primitives; but I believe you could create an array of Objects, and then initialize the elemnets as subtypes of the Object class, i.e., any class. I don't think this would be very practical (in Java); if (for example) you need to store information about people's names with their ages, create a class called "Person" that has those two attributes, then create an array of Persons.


How do you merge two array without using function?

Take another array big enough to hold both array copy content of these two array into new one. You merged two array and haven't used a single function.!

Related questions

What is example of two dimentional array?

a matrix


What are the kinds of arrays?

1. One dimension array 2. Two dimension array 3. Multi dimentional array


Declaration of two dimentional array in functions?

Possible. void foo (void) { int array [10][20]; ... }


How do you initialise a two dimentional array?

C provides rectangular multidimensional arrays. In C, a two-dimensional array is really a one-dimensional array, each of whose elements is an array. An array is initialized by a list of initializations in braces; each row of a two-dimensional array is initialized by a corresponding sub-list. Example of two dimensional array initialization: char array_example[2][4] = { {11, 12, 13, 14}, {21, 22, 23, 24} };


How many dimensions does a two dimentional figure have?

A two dimentional figure has two dementions.


What does a 2 dimensional array do?

A two dimensional array is a one-dimensional array of one-dimensional arrays. That is, just as we can have an array of integers, we can also have an array of integer arrays. This idea can be extended such that we can have an array of two-dimensional arrays (a three-dimensional array), and so on. We typically use a two-dimensional array to represent a table of rows and columns, where each row is a one-dimensional array.


What image does stereomicroscope create?

a 3 dimentional one


Is a rectangular prism a polygon?

no. the definition of polygon is two dimentional and a prism is three dimentional


What is one dimentional array?

A One dimensional array is one in which a set of values are present in it. Ex: int[] myArray = new int[4]; The above statement creates a one dimensional array that can hold 4 values.


What is single dimentional?

A single dimension array is an array with one dimension. It is a collection in memory of one or more elements of the same type. int array[100]; declares an array of int's of size 100 elements. The elements are referenced as array[0], the first one, through array[99], the last one.


Dope vector method for one dimentional array?

Dope Vector Method is use for one dimensional array and also two-dimensional array for one dimensional array we use MA(i)=sa+(i-1)*w MA is Memory Address Sa = Start Address i is subscript W for integer w=2 float=4 char=1 for two dimensional array MA(i,j)=SA{n(i-1)+(j-1)}*W


What two-dimentional shapes are most often associated with three-dimentional forms?

Lines of symmetry