CONTENT
Array
 Collection of data types
 Holds a fixed numbers of values
 Values are of common type
Example
 If we want to store marks of 5 students, we can create an array for this,
int marks[5];
0 1 2 3 4
Declaration of an Array
To Declare an array following three things are specified –
 Data types – int, char, float, double
 Name – to identify an array
 Size – Max number of values that array holds
 Index must be written in square brackets [ ]
 Note – array is declared before using it in a program.
Syntax
 Data type array name[array_size]
Example –
int marks[5]
char num[6]
float num[2]
Creating arrays
 The array index starts from zero
 The last element will be (n-1) considering “n” number of elements
Example - To insert five numbers
int num[5]
1st element 2nd element 3rd element 4th element 5th element
[0] [1] [2] [3] [4]
Address of array elements
 Data elements of arrays are stored in consecutive memory locations
 Storing base address of 1st elements in array is sufficient to calculate
address
Formula: Address, A[k] = Base address (A) + w(k-lower_bound)
Word size
Example
 Given array int marks[4] = { 8,7,9,6}
 Calculate address of marks[3]
 If base address is 100
8 7 9 6
[0] [1] [2] [3]
100 102 104 106
marks
Base address
A[k] = Base address (A) + w(k-lower_bound)
Word size
Length of the array
 Length of array is given by the no. of elements stored in it.
 Formula –
length= Upper_bound – Lower_bound +1
• Upper_bound – index of last element
• Lower_bound - index of first element in array
example
 Let marks be an array of integer are
marks[0] = 8, marks[1] = 4, marks[2] = 9, marks[3] = 8, marks[4] = 6
 Memory representation
Length = Upper_bound – Lower_bound +1
Length = 4 – 0 + 1 = 5
8 7 9 6
[0] [1] [2] [3] [4]
6
Types of array
One- dimensional array
Two- dimensional array
Three- dimensional array
One dimensional array
 An array which has only one subscript is known as
one dimensional array.
Two dimensional arrays
 Represents the list of items using two index.
 The two dimensional (2D) array in c programming is also
known as matrix.
Three-dimensional array
 A 3D array adds another dimension, turning it into an
array of array of arrays.
CONCLUSION
• An array is used to represent a
collection of objects or values, whose
length you know ahead of time.
REFERENCES
• WIKIPEDIA
• QUORA
• OVER IQ
• YOU TUBE
ARRAY
ARRAY

ARRAY

  • 2.
  • 3.
    Array  Collection ofdata types  Holds a fixed numbers of values  Values are of common type
  • 4.
    Example  If wewant to store marks of 5 students, we can create an array for this, int marks[5]; 0 1 2 3 4
  • 5.
    Declaration of anArray To Declare an array following three things are specified –  Data types – int, char, float, double  Name – to identify an array  Size – Max number of values that array holds  Index must be written in square brackets [ ]  Note – array is declared before using it in a program.
  • 6.
    Syntax  Data typearray name[array_size] Example – int marks[5] char num[6] float num[2]
  • 7.
    Creating arrays  Thearray index starts from zero  The last element will be (n-1) considering “n” number of elements Example - To insert five numbers int num[5] 1st element 2nd element 3rd element 4th element 5th element [0] [1] [2] [3] [4]
  • 8.
    Address of arrayelements  Data elements of arrays are stored in consecutive memory locations  Storing base address of 1st elements in array is sufficient to calculate address Formula: Address, A[k] = Base address (A) + w(k-lower_bound) Word size
  • 9.
    Example  Given arrayint marks[4] = { 8,7,9,6}  Calculate address of marks[3]  If base address is 100 8 7 9 6 [0] [1] [2] [3] 100 102 104 106 marks Base address A[k] = Base address (A) + w(k-lower_bound) Word size
  • 10.
    Length of thearray  Length of array is given by the no. of elements stored in it.  Formula – length= Upper_bound – Lower_bound +1 • Upper_bound – index of last element • Lower_bound - index of first element in array
  • 11.
    example  Let marksbe an array of integer are marks[0] = 8, marks[1] = 4, marks[2] = 9, marks[3] = 8, marks[4] = 6  Memory representation Length = Upper_bound – Lower_bound +1 Length = 4 – 0 + 1 = 5 8 7 9 6 [0] [1] [2] [3] [4] 6
  • 12.
    Types of array One-dimensional array Two- dimensional array Three- dimensional array
  • 13.
    One dimensional array An array which has only one subscript is known as one dimensional array.
  • 15.
    Two dimensional arrays Represents the list of items using two index.  The two dimensional (2D) array in c programming is also known as matrix.
  • 17.
    Three-dimensional array  A3D array adds another dimension, turning it into an array of array of arrays.
  • 18.
    CONCLUSION • An arrayis used to represent a collection of objects or values, whose length you know ahead of time.
  • 19.