What is an array in C?

Long Answer
Views 804

Answer:

An Array is a group of similar types of elements. It has a contiguous memory location. It makes the code optimized, easy to traverse and easy to sort. The size and type of arrays cannot be changed after its declaration.

Arrays are of two types:

  • One-dimensional array: One-dimensional array is an array that stores the elements one after the another.

Syntax:

 
  1. data_type array_name[size];  
  • Multidimensional array: Multidimensional array is an array that contains more than one array.

Syntax:

 
  1. data_type array_name[size];  

Example of an array:


#include <stdio.h>  
int main()  
{  
   int arr[5]={1,2,3,4,5}; //an array consists of five integer values.  
   for(int i=0;i<5;i++)  
   {  
       printf("%d ",arr[i]);  
   }  
    return 0;  
}  

Output

1 2 3 4 5

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of C Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.