What is an array in C?

C Programming Language >   Array in C Language >   Single Dimensional Array  

Long Question

860


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


This Particular section is dedicated to Question & Answer only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.




Join Our telegram group to ask Questions

Click below button to join our groups.