Arrays In C Programming – Syntax, Memory, and more.


           Variables are the most common ways of programming in any language, variables are the memory containers that store the respective values of their data type. Variables can be of any data type such as integers, characters, float, double and more. But variables can only store only one value at a time. To store more than one value in a single name you need arrays, arrays are a continuous block of memory that is identified by a single name. Or in other words, arrays are the variables with more than one memory block. Additionally, you can read about our article on important coding skills for kids.

Array declaration:

             Arrays are identified by variable names, the rules for naming the array variable is as same as naming a normal variable. The only difference between a normal and array variable name is that you need to use the square brackets to identify them as an array.

Syntax is :

data_type array_variable_name [number_of_array_elements];

Example :

 int a[7];

This is an example of how you can create an integer array with 7 elements. This array ‘a’ can store 7 integer values. The ‘a’ is known as the array variable and it is what is used to identify the array. The number 7 that is specified inside the square bracket defines the number of elements in an array.

Assigning values to an array :

              Each element in an array is identified by its position in the array. The array elements are positioned as given below:

As you might have noticed in the diagram, the array elements are continuously distributed in the memory. Also, each element in the array is identified by their array index, every array starts with the index 0, hence the last element of an array will always have the index of n-1. The array is distributed along with the index of 0 to n-1.

Array initialization:

               You can initialize the values of an array element by their array index.


a[0] = 1;

Here the array index of 0 will be assigned with the integer value of 1. Likewise, every element in an array will be assigned with the values when the array name and the index are mentioned the value in the array can be accessed.

Here is an example of an array a with 7 elements with values from 1 to 7

Here are some of the examples for array decleration:

int a[10]; //array of 10 integer variables

float f[10]; //array of 10 floating point variables

char c[10]; //array of 10 character variables

double d[10]; //array of 10 double variables

References :

Default image
I'm Karan Dharmalingam, Co-founder of Criss Cross Tamizh. My responsibilities in Criss Cross Tamizh include Head Content Writer and Editor, Video Producer, and Editor. I have always believed that my best work is in the content creation field. The journey of CCT was almost like a bar joke. While talking to my bestie Arun Kumar, he jokingly said how cool it would be if we can have our own websites and YouTube channels. And I also felt the same and right at that moment we started a YouTube channel and it's almost 2 years and we have come a very long way both in business and as humans as well. Thanks for reading nanba/nanbi !!
Articles: 4

Leave a Reply