Array

An array is a sequence of data item of homogeneous value. It is used to store a collection of data but it is often more useful to think of ...

An array is a sequence of data item of homogeneous value. It is used to store a collection of data but it is often more useful to think of an array as a collection of variable of the same type. All array consist of contiguous memory location. The lowest address corresponds to the first element and the highest address to the last element.


Declaration of array
An array declaration is very similar to variable declaration. First a type is given for the element of the array, then an identifier for the array and within square brackets the number of elements in the array. The number of element must be an integer.
Syntax
for one dimensional array
storage_class data_type array_name[size];
Example
int a[5];


for two dimensional array
storage_class data_type array_name[no of row][no of element in each row];
Example
int a[5][4];

Initialization of array
The initializer for an array is a comma separated list of constant expression enclosed in braces {}. The initializer is preceded by an equal sign. If an array is partially initialized, elements that are not initialized receive the value 0 of the appropriate type. We can not initialize more number than the declaration in the array.
Example
int number[3] = {3,5,7};

Multi-dimensional array
Multi-dimensional array are define in much the same manner as one-dimensional array, except that a separate pair of square brackets is required for each subscript. Two-dimensional array will require two pair and three required three pairs of square brackets. Therefore, syntax for multi-dimensional array is,
Syntax
storage_class data_type array_name[expression-1][expression-2]................[expression-n];
Example
float mda[20][10][2];

Passing array to a function
An entry array can be pass through a user define function as an argument. The way in which array is passed to the function differs from passing normal variable to a function.

function declaration, the name of array with appear of empty square bracket is passed as an argument.
Syntax
return_type function_name(data_type name[]);
Example
int sum(int a[]);

In function call the name of an array is passed without brackets as an actual argument.
Example
main()
    int x[10];
    .
    .
    .
    .
    sum(x);

In the function definition the array name is written with a pair of empty square brackets.
Example
void sum(int a[])
{
    ...............
   ...............
}

When an array is passed to function, values of array elements are not passed to the function but the address of first element is passed to function.

COMMENTS

Name

Accident Alert,1,AI,2,Array,1,Aurdino,1,C,2,Computer Graphics,9,Data Science,3,Dataset,1,Decoratot,1,Django,1,ESP32,1,Fixed point/iteration method,1,Greater or smaller,1,html,1,Image Processing,1,JAVA,1,Javascript,22,Machine Learning,1,Matlab,3,Numerical Method,13,OOP,1,Other,3,PHP,1,Point operation,1,Python,11,Raspberry pi,1,Recommendation System,1,Regression,1,Reservation System,1,Robotics,1,Simulation,2,sine wave,1,String Handling Function,1,Web scrap,1,Webpage,1,
ltr
item
COMPUTER PROGRAMMING: Array
Array
https://ds055uzetaobb.cloudfront.net/image_optimizer/7bfe2713ecaf427164d14018608b826ffbeea531.jpg
COMPUTER PROGRAMMING
https://computerprogram4ru.blogspot.com/2017/08/array.html
https://computerprogram4ru.blogspot.com/
https://computerprogram4ru.blogspot.com/
https://computerprogram4ru.blogspot.com/2017/08/array.html
true
8672391763020279633
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy