Arrays in C programming
An array is a group (or collection) of same data types. For example an int array holds the elements of int types while a float array holds the elements of float types.
How to declare Array in C
int num[35]; /* An integer array of 35 elements */ char ch[10]; /* An array of characters for 10 elements */
Similarly an array can be of any data type such as double
, float
, short
etc.
How to access element of an array in C
You can use array subscript (or index) to access any element stored in array. Subscript starts with 0, which means arr[0]
represents the first element in the array arr.
C Array – Memory representation
More Topics on Arrays in C:
2D array – We can have multidimensional arrays in C like 2D and 3D array. However the most popular and frequently used array is 2D – two dimensional array. In this post you will learn how to declare, read and write data in 2D array along with various other features of it.
Passing an array to a function– Generally we pass values and variables while calling a function, likewise we can also pass arrays to a function. You can pass array’s element as well as whole array (by just specifying the array name, which works as a pointer) to a function.
Pointer to array – Array elements can be accessed and manipulated using pointers in C. Using pointers you can easily handle array. You can have access of all the elements of an array just by assigning the array’s base address to pointer variable.