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
A simple formula to declare arrays in C++ is as:
1. For 1D or one dimensional array:
data_type
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
For example, to declare any floating point, 2D array, with 3 rows and 5 columns, I will write
float sample [3][5];
//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);
}
}
My answer is specific for C/C++ programming languages.
Here's are examples:
int[] array;
int array[];
int[] array = {1, 2, 3};
This is done somewhat differently in different programming languages, due to syntax differences.
Basically you declare an array whose elements are integers.
Example: char *argv[]
int array[2][10][20];
int array_name [100];
int[] marks = new int[3]; int marks[3];
#include <stdlib.h> int **array1 = malloc(nrows * sizeof(int *)); for(i = 0; i < nrows; i++) array1[i] = malloc(ncolumns * sizeof(int));
int findMax(int *array) { int max = array[0]; for(int i = 1; i < array.length(); i++) { if(array[i] > max) max = array[i] } return max; }
int array[2][10][20];
int array_name [100];
Yes: int[] integerArray;
int[] marks = new int[3]; int marks[3];
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á!
#include <stdlib.h> int **array1 = malloc(nrows * sizeof(int *)); for(i = 0; i < nrows; i++) array1[i] = malloc(ncolumns * sizeof(int));
typedef float (*pt_func)(int, int); pt_func arr[3];another way:float (*pt_func[3])(int, int);
int findMax(int *array) { int max = array[0]; for(int i = 1; i < array.length(); i++) { if(array[i] > max) max = array[i] } return max; }
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
typedef float (*pt_func)(int, int); pt_func arr[3];another way:float (*pt_func[3])(int, int);
void bubblesort (int* array, int size) { if (!array size<2) return; int last_swap = size; while (last_swap>0) { int n=last_swap; for (int i=1; i<last_swap; ++i) { if (array[i]<array[i-1]) { array[i]^=array[i-1]^=array[i]^=array[i-1]; n=i; } last_swap = n; } }
public static int[] reverseArray(int[] array) { int i = 0, j = array.length - 1; for (i = 0; i < array.length / 2; i++, j--) { int temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; }