answersLogoWhite

0


Best Answer

In what language?

c and c++

a 5 x 5 array of Int

int nMultiIntArray[5][5];

Answer:

in java

int array[][]=new int[5][5];

in vb

dim array(5,5) as Integer

User Avatar

Wiki User

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

Wiki User

9y ago

C-style static array:

int x[10][5]; // an array of arrays (10 arrays of 5 elements each)

C++ static array:

std::array<std::array<int, 5>, 10> a;

C++ dynamic array (vector):

std::vector<std::vector<int>> v;

In a C++ dynamic array, each dimension can have a different number of elements. A classic example of a multidimensional array is an array of strings, where each string is a character array of variable length:

std::vector<std::string> s;

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Syntax of an array

type var_name[];

or

type []var_name;

Where

type- Type is an valid data type or reference name.

var_name- Valid identifier where is accepted by Java compiler.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

There are two types of arrays: static and dynamic.

A two dimensional array is one array, each element of which consists of another array. Declaring a two-dimensional static array is as follows:

[][];

For instance:

int myintarray[10][5];

This sets up an array of 50 elements: 10*5. Assuming intis 4 bytes large, the total size of this array is 200 bytes. The outermost array is indexed from 0 to 9, and the innermost arrays are indexed from 0 to 4. Thus, "maxindex+1" above.

Dynamic arrays are created using a memory allocation function (i.e. malloc()). The above array declaration could be rewritten as follows:

int **myintarray, index;

myintarray=(int**)malloc(sizeof(int*)*10);

for (index=0; index<10; index++)

myintarray[index]=(int*)malloc(sizeof(int)*5);

The outermost array has a block of memory 40 bytes long on a system using 32-bit pointers. Each array within has a block of memory 20 bytes long for a 32-bit int.

Please note that using constants like above (10 and 5) is not recommended, and you should use #define statements to help prevent invisible bugs. For instance, if you later changed 10 to 20 in the allocator, but neglected to make the same change in a for() iterator loop, memory that had been allocated would not be used; conversely, making a similar change in the iterator but not the allocator would lead to a segmentation fault condition (segfault).

So either of the following is instead recommended:

#define OUTARRSIZE 10

#define INARRSIZE 5

int myintarray[OUTARRSIZE][INARRSIZE];

Or:

#define OUTARRSIZE 10

#define INARRSIZE 5

int **myintarray, index;

myintarray=(int**)malloc(sizeof(int*)*OUTARRSIZE);

for (index=0; index

myintarray[index]=(int*)malloc(sizeof(int)*INARRSIZE);

More information on arrays and pointers is available at the related links below.

(Note that the code above has not been tested, and is available for demonstrative purposes only.)

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is declaration syntax of an array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is array Explain with syntax?

an array is a collection of the same data type.


When does generally declaration syntax error occur?

All syntax errors occur at compile time.


What is the correct syntax for declaring and initializing an array that contains the numers 0-9?

The syntax is: int a[10]; for (int i=0; i&lt;10; ++i) a[i]=i;


What is the syntax of function?

Function declaration, definition, or calling? Pick one.


What is the correct syntax of the declaration which defines the xml version?

&lt;?xml version="1.0"?&gt;


What is the correct syntax for declaring and initializing an array that contains the numbers 0-9?

int x[]={0,1,2,3,4,5,6,7,8,9};


Declaration of two dimentional array in functions?

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


Why array index always starts with zero?

Because that's how the language is defined. In C, C++, and many other languages, array indecies start with zero. This is by convention, and it also reflects the fact that, in C and C++, array-index syntax can also be expressed in pointer-offset syntax. The pointer locates the first element of the array, and the offset indicates how many elements to skip. If a is an array name, then the expression a[n] is completely identical to the expression *(a+n), and vice versa.


Create an anonymous array in java?

An anonymous array in Java is just an array with its contents declared at instantiation. Normal array declaration: int[] nums = new int[3]; nums[0] = 0; nums[1] = 1; nums[2] = 2; Anonymous array declaration: int[] nums = new int[] {0,1,2}; The two examples above will each result in the same array.


What is syntax in c plus plus for declaring a variable?

type variable {[optional array size]} {= optional initializer};


What are the basic syntax of c program?

You have to be more specific. What part of C syntax? Do you want the syntax for outputing a number or sentence, do you want to syntax for creating a array, struct, a user defined function or what? #include iostream using namespace std; int main { cout &lt;&lt; "Hello World!" &lt;&lt; endl; return 0; };


How array differ from ordinary variable?

ordanry variable store one value at a time. arrays are used for storing more than one value at a time in a single variable name ordanry variable doesnt have subscript. array must have subscript syntax for ord. variable Datatype v1,v2...... syntax for array variable Datatype v1[n1],v2[n2].....