Q1 C Array, What are Arrays in C. Properties, Advantages, Disadvantages, Declaration and Initialization of Arrays.

What are Arrays in C. Why we need arrays and how to use arrays in programs

Definition of C Array:

An array is a collection of similar type of data items which stored items at contiguous memory locations, first element stores at smallest memory location. Arrays are knows as Derived Data Types in C.

Properties of C Array:

  • Arrays can store the primitive type of data such as int, float, double, char etc. It can also store the collection of derived data types such as pointer and structures.
  • Each element present in array of same data type with the same size. (int = 4 bytes).
  • Mentioning the dimension of the array is optional at declaration.
  • We can randomly access the element using its index number.

Advantages of C Array:

  • We can access the data with less line of code.
  • We can easily traverse the elements in the arrays.
  • Sorting of elements is easy.
  • We can easily access random element.

Disadvantages of C Array:

  • If we define the size of array at declaration, we can’t exceed the limit.

Declaration of C Array:

data_type array_name[array_size]; 

Examples:

int numbers[5];

Initialization of C Array:

array_name[index] = value;
numbers[0] = 50;
numbers[1] = 20;
numbers[2] = 10;
numbers[3] = 60;
numbers[4] = 90;

Declaration with Initialization of C Array:

int num[5] = {2, 4, 12, 5, 11};
int n[] = {2, 3, 6, 2, 1};

* In such case mentioning the size of array is optional.

First C Program with Array:

Output:

80
60
70
85
75
Lokesh Kumar: Being EASTER SCIENCE's founder, Lokesh Kumar wants to share his knowledge and ideas. His motive is "We assist you to choose the best", He believes in different thinking.
Related Post
Leave a Comment

This website uses cookies.