answersLogoWhite

0

How do you declare an int array?

Updated: 8/10/2023
User Avatar

Wiki User

11y ago

Best Answer

we define the array is

Array array[]={1,2,3,4,5} this is the integer Array

Array array[]={"apple","banana","carrot","mango"} this is the String Array

User Avatar

Wiki User

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

Wiki User

11y ago

A simple formula to declare arrays in C++ is as:

1. For 1D or one dimensional array:

data_type name_of_array[size_of_array] ;

For example, if I want to declare a 1D array named marks, of integer type with a size 10, I will write

int marks [10];

2. For 2D or two dimensional arrays:

data_type name_of_array[number_of_rows][number_of_columns] ;

For example, to declare any floating point, 2D array, with 3 rows and 5 columns, I will write

float sample [3][5];

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

//array understanding program

import java.io.*;

class arraydemo1

{

public static void main(String args[])throws IOException

{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println("Number of subjects are:");

int n=Integer.parseInt(br.readLine());

int marks[]=new int[n];

for(int i=0; i<n;i++)

{

System.out.println("enter marks:");

marks[i]=Integer.parseInt(br.readLine());

}

int total=0;

for(int i=0; i<n;i++)

{

total=total+marks[i];

}

System.out.println("total marks are:"+total);

}

}

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

My answer is specific for C/C++ programming languages.

  • For declaration of integer array in C/C++
Example:
int arrayName[n];
// where n is the number of elements


  • For initialization of integer array in C/C++
Example:
int oddNumbers[5] = {1, 3, 5, 7, 9};
This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Here's are examples:

int[] array;

int array[];

int[] array = {1, 2, 3};

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

This is done somewhat differently in different programming languages, due to syntax differences.

Basically you declare an array whose elements are integers.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Example: char *argv[]

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you declare an int array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you declare an array alpha of 10 rows and 20 columns of type int?

int array[2][10][20];


Declare an array of 100 integers?

int array_name [100];


Is it possible to declare an array of numbers in an integer form?

Yes: int[] integerArray;


Declare an integer array marks that can be used to store 3 elements?

int[] marks = new int[3]; int marks[3];


What are the application of array in c?

Well, instead of having to type stuff like this: int foo = 0; int bar = 0; Etc., we can just declare an array of ints: int arrayOfInts[2]; Voil&aacute;!


How do you declare an N-Dimensional array using Malloc?

#include &lt;stdlib.h&gt; int **array1 = malloc(nrows * sizeof(int *)); for(i = 0; i &lt; nrows; i++) array1[i] = malloc(ncolumns * sizeof(int));


How will you declare an array of three function pointers where each function receives two int and returns float?

typedef float (*pt_func)(int, int); pt_func arr[3];another way:float (*pt_func[3])(int, int);


Write a c program to find the maximum value of 25 element in an array?

int findMax(int *array) { int max = array[0]; for(int i = 1; i &lt; array.length(); i++) { if(array[i] &gt; max) max = array[i] } return max; }


How do you initialize an array variable in java program?

An array in java is a collection of items stored into a single unit. The array has some number of slots (elements), each slot in the array can hold an object or a primitive value. Arrays in java are objects that can be treated just like other objects in the languageArrays can contain any type of element value , but we can't store different types in a single array. We can have an array of integers or an array of strings or an array of arrays.To create an array in java ,use three steps1. Declare a variable to hold the array2. Create a new array object and assign it to the array variable3. Store things in that array


How will you declare an array of three functions pointer where each function receives two ints and returns a float?

typedef float (*pt_func)(int, int); pt_func arr[3];another way:float (*pt_func[3])(int, int);


What is a implementation on n numbers of term in bubble sorting?

void bubblesort (int* array, int size) { if (!array size&lt;2) return; int last_swap = size; while (last_swap&gt;0) { int n=last_swap; for (int i=1; i&lt;last_swap; ++i) { if (array[i]&lt;array[i-1]) { array[i]^=array[i-1]^=array[i]^=array[i-1]; n=i; } last_swap = n; } }


Write a c program to reverse an array without using another array?

public static int[] reverseArray(int[] array) { int i = 0, j = array.length - 1; for (i = 0; i &lt; array.length / 2; i++, j--) { int temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; }