Limitations of Array | Programming and Data Structures - Computer Science Engineering (CSE) PDF Download

What are the limitations of array in C language?

Arrays are a kind of data structure that can store a fixed-size sequential collection of elements of the same type.
An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.

Limitations

The limitations of an array are explained below:

  • An array which is formed will be homogeneous. That is, in an integer array only integer values can be stored, while in a float array only floating value and character array can have only characters. Thus, no array can have values of two data types.
  • While declaring an array, passing size of an array is compulsory, and the size must be a constant. Thus, there is either shortage or wastage of memory.
  • Shifting is required for insertion or deletion of elements in an array.
  • An array doesn’t check boundaries: In C language, we cannot check, if the values entered in an array are exceeding the size of that array or not.
  • Data that is entered with the subscript, exceeds the array size and will be placed outside the array. Generally, on the top of the data or the program itself.
  • This will lead to unpredictable results, to say the least. Also, there will be no error message to warn the programmer of going beyond the array size. In some cases, the program may hang.

Thus, the following program can give undesired result:
int a[1θ],i;
for(i=θ;i<=2θ;i++)
a[i]=i;

Example:
Following is the C program to display sum of two arrays:
#include<stdio.h>
void main(){
   //Declaring array with compile time initialization//
   int array1[5],array2[5],sum[5];
   //Declaring variables//
   int i;
   //Printing O/p using for loop//
   printf("Enter the values of array1 :\n");
   for(i=θ;i<5;i++){
      printf("array1[%d] : \n",i);
      scanf("%d",&array1[i]);
   }
   printf("Enter the values of array2 :\n");   for(i=θ;i<5;i++){
      printf("array2[%d] :\n",i);
      scanf("%d",&array2[i]);
   }
   printf("Elements in the sum of array1 and array2 are:\n ");
   for(i=θ;i<5;i++){
      sum[i]=array1[i]+array2[i];
      printf("%d ",sum[i]);
   }
}

Output
When the above program is executed, it produces the following result:
Enter the values of array1:
array1[θ] : 2
array1[1] : 3
array1[2] : 1
array1[3] : 2
array1[4] : 3
Enter the values of array2:
array2[θ] : 4
array2[1] : 5
array2[2] : 3
array2[3] : 2
array2[4] : 1
Elements in the sum of array1 and array2 are: 6 8 4 4 4

The document Limitations of Array | Programming and Data Structures - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Programming and Data Structures.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
119 docs|30 tests

Top Courses for Computer Science Engineering (CSE)

FAQs on Limitations of Array - Programming and Data Structures - Computer Science Engineering (CSE)

1. What is an array in programming?
An array is a data structure that stores a fixed-size sequence of elements of the same type. It allows efficient access to individual elements using an index.
2. What are the advantages of using arrays?
Arrays provide several advantages, including: - Efficient access to elements: Array elements can be accessed directly using their index, which allows for quick retrieval. - Memory efficiency: Arrays use contiguous memory locations, which reduces memory overhead compared to other data structures. - Simplified code: Arrays simplify code logic by allowing elements to be stored sequentially and accessed using loops or iterators. - Easy implementation of algorithms: Many algorithms and operations, such as sorting and searching, are designed to work with arrays efficiently.
3. What are the limitations of arrays?
Arrays have certain limitations, including: - Fixed size: Arrays have a fixed size, which means they cannot be resized dynamically. Once the size is defined, it remains constant throughout the program execution. - Inefficient insertion and deletion: Insertion and deletion operations in arrays can be inefficient, especially when performed in the middle of the array. All elements after the insertion or deletion point need to be shifted, resulting in extra time complexity. - Wasted memory: If an array is declared with a large size but only a few elements are used, it can lead to wasted memory space. - Lack of flexibility: Arrays require elements to be of the same type, limiting their flexibility in handling heterogeneous data.
4. How can the size of an array be determined in programming languages?
In most programming languages, the size of an array can be determined using the "length" property or function. For example, in C++, the "size()" function can be used to get the size of an array. In Python, the "len()" function can be used to determine the length of an array.
5. Can arrays store elements of different data types?
In most programming languages, arrays are designed to store elements of the same data type. However, there are some languages, like Python, that allow arrays to store elements of different data types by using a concept called "lists." Lists in Python can contain elements of different types, providing greater flexibility compared to traditional arrays.
119 docs|30 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

pdf

,

past year papers

,

video lectures

,

Semester Notes

,

Free

,

Viva Questions

,

Limitations of Array | Programming and Data Structures - Computer Science Engineering (CSE)

,

Sample Paper

,

MCQs

,

Extra Questions

,

Exam

,

Objective type Questions

,

mock tests for examination

,

study material

,

Limitations of Array | Programming and Data Structures - Computer Science Engineering (CSE)

,

Previous Year Questions with Solutions

,

Limitations of Array | Programming and Data Structures - Computer Science Engineering (CSE)

,

practice quizzes

,

Summary

,

Important questions

,

ppt

,

shortcuts and tricks

;