Technology has advanced to the point where programming has become an essential part of our lives. We use software and applications for communication, entertainment, education, and work, and these are all built on programming languages.

An Array in C programming

An array is a collection of similar data type which is stored in a consecutive memory location in a single variable. It is derived data type in C, which is constructed from the fundamental data type of C language. The individual values in an array are called elements. If it contains int data type then all the data of the array must be int, if float then all the data must be a float.

Each array element is referred by specifying the array name followed by one or more subscript with each subscript enclosed in square brackets. In C subscript starts at zero rather than one and each subscript must be expressed as a non-negative integer. The subscript is used to denote the size of the array.
.

Advantages of array
  • Code Optimization: Less code is required, one variable can store numbers of value.
  • Easy to traverse data: By using array easily retrieve the data of array.
  • Easy to sort data: Easily sort data using the swapping technique.
  • Random Access: With the help of an array index you can randomly access any elements from the array.
 Disadvantages of array
  •  Fixed-size
                      Whatever size, we define at the time of declaration of the array, we cannot change their size, if you need more memory in that time we cannot increase memory size, and if you need less memory in that case also there is wastage of memory.

  • Declaring Array
                            To declare an array in C you need to declare data type and size of an array.

        Syntax
  
             datatype  arrayName[SIZE]


       Example 
             
               int rollno[20];

        rollno varriable can store 20 values in it.


Initialization of array 

           Initializing is a process to initialize the value in array variable. This is happen in two ways, initialize array one by one or all elements initialize once.

         Initialization array one by one
  int rollno[3];

                     rollno[0]=4;
                     rollno[1]=2;
                     rollno[2]=5;
                   
            
             Initialization array at once
                           int roll[]={4,2,5};

                     roll[2]         // here 2 is index value and return 5;

Keynote on Array
  • The array has 0 as the first Index. 
  •  If the size of an array in n, to access last element, [n-1] index is used
Share:

Program To Print Multiplication table of 2, 3 and 4

To print the multiplication table we have to use for loop. Inner loop is used here where two varriable are plays vital role i.e. i and j. Symbolic letter "x" and "=" are also being used to give illusion of multiplication.

So, the program begins here

This program takes two varriable i andd j and are multiplied in the inner loop. In a first loop the value of i remains same while the value of j increases by 1. Integer specifier are used. Here new line is printed as the loop of j ended the new line begins.


Output
Here, all the multiplication table is not shown because the output window is small.
Share:

Translate

Wikipedia

Search results