Hello friends...
Today we are going to explain a very important topic of C programming i.e.,ARRAY.
So without wasting much time,let us move forward to describe our topic:-ARRAY.

Sometimes we need to store multiple values and other data items of same kind and same field.We can do this by declaring various individual variables and assigning them their respective values,but it'll be very difficult and will be a very lengthy process and also very time taking.
To reduce these kind of difficulties and to save our time.


  ARRAY

An ARRAY is a collection of similar kinds of data type whose memory is allocated in a continuous block of memory.It is a data structure,processes many elements with same data types.
*It is fixed in size that means you can't increase the size of array at the run time\execution time.
*It is collection of homogeneous elements.

                 

ADVANTAGES OF ARRAY:-

1).One array variable can store multiple values of same data type.
2).The main advantage of array is we can represent multiple values under the same name.
3).It can be used for implementation of other data structures like linked lists,queues,trees,graphs,stacks,etc.
4).2-D array can be used to represent matrices.

DISADVANTAGES OF ARRAY:-

1).The memory allocated to array variable can't be changed.
2).We must know number of elements to be stored in an array variable in the starting.
3).The elements of array are stored in consecutive memory locations.So insertions and deletions are very difficult and time consuming.
4).Though array is fixed in size.If we allocate more memory than requirement,the the memory space will be wasted,and if allocate less memory than requirement then it will create problem.

INITIALIZING AN ARRAY:-

Initialization of an array variable is way similar to initialization of other variables except that you must put a square bracket[] after the array variable name.Square brackets must contain the number of elements that are going to be stored in that particular array variable.
SYNTAX:
      datatype array_name[size];

EXAMPLE:
      int arr[5]; //arr be the array variable of integer datatype containing 5 elements

DECLARING AN ARRAY:-

Declaring an array variable includes assigning value to the array or assigning values to elements of an array.Values of an array can be assigned by us or as well as can be entered by the user at the run time for the execution of the program.
We can assign values to the array in curly braces{} separated by comma(,).
SYNTAX: 
      datatype array_name[size]={elements of array};

                 

EXAMPLE:
      int arr[3]={5,10,15}; //arr be the array variable holding three values i.e,5,10,15
   
      #include<stdio.h>
      void main()
      {
      int arr[3];
      int i;
      for(i=0;i<3;i++)
      {
      scanf("%d",&arr[i]);
      printf("array element are:%d\n",arr[i]);
      }
      }

TYPES OF ARRAY:-

There are mainly two types of array namely-
a).Single Dimensional Array OR One Dimensional Array
b).Multi Dimensional Array 

                 
                


ONE DIMENSIONAL ARRAY/SINGLE DIMENSIONAL ARRAY:-

                   

One Dimensional array is a kind of linear array.An array which has only one subscript is known as one dimensional array.
Excessing its elements involves a single subscript which can either represent a row or a column.

SYNTAX:
      datatype array_name[size];
               OR
      datatype array_name[size]={elements of array};

EXAMPLE:
     #include<stdio.h>
     void main()
     {
     int arr[5],i;
     for(i=0;i<5;i++)
     {
     printf("Enter a value of arr[%d]",i);
     scanf("%d".&arr[i]);
     }
     printf("The array elements are :\n");
     for(i=o;i<5;i++)
     {
     printf("%d\t",arr[i]);
     printf("\n");
     }
     }

MULTI DIMENSIONAL ARRAY:

Multi dimensional array is an array that has one than one dimension.It is an array of array i.e., an array that has multiple levels.Multi dimensional array have multiple subscripts.
2-D array is the simplest multi dimensional array.2-D array is also called a matrix or a table of rows and columns.


SYNTAX:
     datatype array_name[size1][size2][size3]...[sizen];
                           OR
     datatype array_name[size1][size2][size3]...[sizen]={elements of array};
where size1,size2,size3,sizen are the subscripts or size of dimensions.

EXAMPLE:
     #include<stdio.h>
     int main()
     {
     int arr[2][3]; 
     int i,j;
     for(i=0;i<2;i++)
     {
     printf("Enter value for arr[%d][%d]:",i,j);
     scanf("%d",&arr[i][j]);
     }
     printf("Two dimensional array elements:\n");
     for(i=0;i<2;i++)
     {
     for(j=0;j<3;j++)
     {
     printf("%d",arr[i][j]);
     if(j==2)
     {
     printf("\n");
     }   
     }
     }
     return 0;
     }

   

Comments

  1. Very nice RAHSHREE ๐Ÿ‘๐Ÿ‘

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Very nice work Rahshree
    (Update needed)

    ReplyDelete
  4. Good work... You have to explain it in ease language .๐Ÿ‘๐Ÿป๐Ÿ‘๐Ÿป

    ReplyDelete
    Replies
    1. Thanks...surely going to consider ur advice

      Delete
  5. Good work ... Rahat๐Ÿ‘๐Ÿ‘

    ReplyDelete
  6. Good work. .. Both of uhh๐Ÿ‘๐Ÿ‘

    ReplyDelete
  7. I m also bca student but 1 sem so henry fayol aur bc bata dijiye rahshree mam

    ReplyDelete
  8. Your haenry fayol and ob matter was ossum
    Gud work rahshree mam

    ReplyDelete
    Replies
    1. Thank you so much...need all of urs support n appreciation...we get motivated by these types of cmmnts

      Delete
  9. This comment has been removed by a blog administrator.

    ReplyDelete
  10. Management ki or topics clear kar dijiye. .
    Nice...������������

    ReplyDelete
    Replies
    1. Let us know which topic u want to be explained briefly...

      Delete
  11. Yrr rahat accounts ki problm clear
    Karo plzz...

    ReplyDelete
  12. Yrr rahat and shreeyanshi gud
    ...proud of u๐Ÿ‘๐Ÿ‘

    ReplyDelete

Post a Comment

Popular Posts