SlideShare a Scribd company logo
A
                                                              R
                                                              R
                                                              A
                                                              Y
              Prakash Khaire
              Prakash Khaire
The Mandvi Education Society Institute of Computer Science
 The Mandvi Education Society Institute of Computer Science
                                                              S
• It is derived data type.
• An array is a very popular and useful data
  structure used to store data elements in
  successive memory locations.
• It is known as “Composite data structure” as
  more than one element is stored in a sequence.
• It permits only homogenous data.
• An array can be declared of any standard or
  custom data type.
• The array of character(strings) type works
  somewhat differently from an array of
  integers, floating numbers.
• Array elements can be accessed by its position
  in the array called as index.
• Values in an array are identified using array
  name with subscripts.
• It is also known as subscripted variable.
• The array can be done as under
  int a[5] = {1, 2, 3, 4, 5};

       Calling array elements
       a[0]     Refers to 1st element i.e. 1
       a[1]     Refers to 2nd element i.e. 2
       a[2]     Refers to 3rd element i.e. 3
       a[3]     Refers to 4th element i.e. 4
       a[4]     Refers to 5th element i.e. 5
Size: Number of elements or capacity to store elements in an array is called its size. It is always mentioned
in brackets “[ ]”.

Type : Type refers to data type. It decides which type of element is stored in the array. It also instructs the
compiler to reserve memory according to data type.

Base : The address of the first element(0th) is a base address. The array name itself stores address of the
first element.

Index : The array name is used to refer to the array element. For example, num[x], num is array name and x
is index. The value of x begins from 0 to onwards depending on the size of the array. The index value is
always an integer value.

Range : Index of an array i.e. value of x varies from lower bound to upper bound while writing or reading
elements from an array. For example in num[100] the range of index is 0 to 99.

Word : It indicates the space required for an element. In each memory location, computer can store a data
piece. The space occupation varies from machine from machine to machine. If the size of element is more
than word (one byte) then it occupies two successive memory locations. The variable of data type int, float,
long need more than one byte in memory.
1.   The Declaration int a[5] is the creation of five variables of integer types
     in memory. Instead of declaring five variables for five values, the
     programmer.

2.   All the elements of an array share the same name, and they are
     distinguished from one another with the help of the element number.
3.   The element number in an array plays a major role for calling each
     element.
4.   Any particular element of an array can be modified separately without
     disturbing             the               other              elements.

     int a[5] = {1, 2, 3, 4, 5}
5.   Any element of an array a[] can be assigned/equated to another
     ordinary variable or array variable of its type.
6.    An array elements are stored in contiguous memory
                0         1         2        3         4
                10        20        30       40        50
                1000      1002      1004     1006      1008

7.    Once the array is declared, its lowest boundary cannot be changed but upper
      boundary can be expanded.
8.    We know that an array name itself is a pointer. Though it is a pointer, it does
      not need ‘*’ operator. The brackets “[]” automatically denote that the variable
      is a pointer.
9.    All the elements of an array share the same near, and they are distinguished
      from one another with the help of the element number.
10.   The amount of memory required for an array depends upon the data type and
      the number of elements. The total size in bytes for a single dimensional array is
      compared as shown below.
      Total bytes = sizeof(data type) x size of array
11.   The operations such as insertion, deletion of an element can be done with list
      but cannot be done with an array. Once an array is created we cannot remove
      or insert memory location. An element can be deleted, replaced but the
      memory location remains as it is.
12.   When an array is declared and not initialization, it contains garbage values. If
      we declared an array as static, all elements are initialized to zero.
Mesics lecture 8   arrays in 'c'
• A collections of variables are given one variable
  name using only one subscript and such a
  variable is called a single-subscripted variable or
  one dimensional array.
• Syntax
      data_type ArrayName[size];

     data_type : is a valid data type like int, float or char
    Arrayname : is a valid identifier
    size : maximum number of elements that can
               be stored in array
• Initialization of an array – int a[5]
   – Type of array variable is “integer”.
   – Its variable name is a.
   – 5 is the size of the array.
• The elements of an array are stored in
  contiguous memory locations.
     Element   a[0]    a[1]   a[2]    a[3]   a[4]
      Value     5       4      6       3      7
     Address   2050    2052   2054    2056   2058
 Array index starts with zero
 The last index in an array is num – 1
where num is the no of elements in a array
 int a[9] is an array that stores 9 integers

    index         0    1     2     3   4    5     6     7     8

  elements

Memory address   100   102   104   106 108 110   112   114   116
• An elements of an array must be initialized,
  otherwise they may contain “garbage” value.
• An array can be initialized at either of the
  following stages
  – At compile time
  – At run time
• We can initialize the elements of arrays in the same way as
  the ordinary variables when they are declared.
   type array_name[size] = {list of values};
• For example,
   int number[3] = {5,10,15};
   float total[5] ={0.0, 15.75, -10.9};
• The size may be omitted. In such cases, the compiler allocates
  enough space for all initialized elements.
   int counter[] = {1,1,1,1};
• The character array may be initialized in the similar manner
  char name[] = {‘v’,’i’,’k’,’a’,’s’,’0’}; or
  char name[] = “vikas”;
• An array can be explicitly initialized at run time.
void main()
{
  int MyArray[5],i;
  for(i=0;i<5;i++)
  {
       MyArray[i] = i * 10;
  }
  getch();
}
• There could be situations where a table of values will have to
  be stored.
         Name/Marks   Science    Maths        English
         Dhrumit      45         48           42
         Uzer         48         44           44
         Prakash      20         14           2

• C allows us to define such tables of items by using two-
  dimensional arrays.
• The two dimensional array are declared as follows
   type array_name[row_size][column_size];
int MyArray[3][3];


         0,0          0,1   0,2
         1,0          1,1   1,2
         2,0          2,1   2,2



0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2
int MyArray[3][3] = {0,0,0,1,1,1,2,2,2};

int MyArray[3][3] = {{0,0,0},{1,1,1},{2,2,2}};

int MyArray[][] = {
                      {0,0,0},
                      {1,1,1},
                      {2,2,2}
                 }
int MyArray[2][3] = {{1,1}, {2}};
  In above, the remaining elements will be initialized to zero.

int MyArray[3][5] = {{0},{0},{0}};
  When all the elements are to be initialized to zero, the
  above statement can be used.

int MyArray[][] = {0,0};
  The first two elements will be initialized explicitly while the
  other elements will be initialized implicitly to zero.
int MyArray[2][3] = {{1,1}, {2}};
  In above, the remaining elements will be initialized to zero.

int MyArray[3][5] = {{0},{0},{0}};
  When all the elements are to be initialized to zero, the
  above statement can be used.

int MyArray[][] = {0,0};
  The first two elements will be initialized explicitly while the
  other elements will be initialized implicitly to zero.
• C allows arrays of three or more dimensions.
  The exact limit is determined by the compiler.
• The general form of a multi-dimensional array
  type array_name[s1][s2][s3]…[sm];
  • Where si is the size of ith dimension.
  • For exmaple
  int MyArray[2][3][4];
0,0         0,1         0, 2         0,3
      1,0         1,1         1,2          1,3
0,0         0,1         0,2          0,3
1,0         1,1         1,2          1,3
2,0         2,1         2,2          2,3

More Related Content

PDF
PPTX
Arrays In C Language
PPT
Arrays Class presentation
PPTX
Arrays in c
PPTX
Arrays in java
PPTX
PPTX
Array in c++
Arrays In C Language
Arrays Class presentation
Arrays in c
Arrays in java
Array in c++

What's hot (20)

PPT
Chap09
PDF
Lecture17 arrays.ppt
PPTX
Arrays In C++
PPTX
Array in c programming
PPTX
Array in c language
PPTX
Presentation on array
PPTX
Introduction to Array ppt
PPTX
Array in C
PPT
Arrays Basics
PPT
Arrays in c
PDF
An Introduction to Programming in Java: Arrays
PPT
Array in c
PPTX
Java arrays
PPT
Java Arrays
PPTX
Array in C# 3.5
PPT
One dimensional 2
PPTX
Arrays basics
PPTX
Arrays in c language
PPTX
A Presentation About Array Manipulation(Insertion & Deletion in an array)
PPSX
C Programming : Arrays
Chap09
Lecture17 arrays.ppt
Arrays In C++
Array in c programming
Array in c language
Presentation on array
Introduction to Array ppt
Array in C
Arrays Basics
Arrays in c
An Introduction to Programming in Java: Arrays
Array in c
Java arrays
Java Arrays
Array in C# 3.5
One dimensional 2
Arrays basics
Arrays in c language
A Presentation About Array Manipulation(Insertion & Deletion in an array)
C Programming : Arrays
Ad

Viewers also liked (20)

PDF
Unit 1.3 types of cloud
PDF
Unit 1.1 introduction to cloud computing
PDF
Lecture19 unionsin c.ppt
PDF
Unit 1.2 move to cloud computing
PDF
Unit 1.4 working of cloud computing
PDF
Lecture 12 css_fonts
PDF
Introduction to computer_and_its_structure
PDF
Introduction to css
PDF
Lecture 11 css_inculsion
PDF
Program development cyle
PDF
Lecturer23 pointersin c.ppt
PDF
Computer programming programming_langugages
PDF
Html phrase tags
PDF
Lecture15 comparisonoftheloopcontrolstructures.ppt
PDF
Lecture21 categoriesof userdefinedfunctions.ppt
PPT
Mesics lecture 5 input – output in ‘c’
PPT
Mesics lecture 3 c – constants and variables
PDF
Lecture 7 relational_and_logical_operators
PDF
Lecture7relationalandlogicaloperators 110823181038-phpapp02
PPT
Mesics lecture files in 'c'
Unit 1.3 types of cloud
Unit 1.1 introduction to cloud computing
Lecture19 unionsin c.ppt
Unit 1.2 move to cloud computing
Unit 1.4 working of cloud computing
Lecture 12 css_fonts
Introduction to computer_and_its_structure
Introduction to css
Lecture 11 css_inculsion
Program development cyle
Lecturer23 pointersin c.ppt
Computer programming programming_langugages
Html phrase tags
Lecture15 comparisonoftheloopcontrolstructures.ppt
Lecture21 categoriesof userdefinedfunctions.ppt
Mesics lecture 5 input – output in ‘c’
Mesics lecture 3 c – constants and variables
Lecture 7 relational_and_logical_operators
Lecture7relationalandlogicaloperators 110823181038-phpapp02
Mesics lecture files in 'c'
Ad

Similar to Mesics lecture 8 arrays in 'c' (20)

PDF
Arrays
PDF
Arrays and library functions
PPT
Arrays
PPTX
unit 2.pptx
PPT
arrayy.ppt
PPTX
Array in C
PPTX
Arrays in C language
PPTX
ARRAYS.pptx
PPTX
Arrays in Data Structure and Algorithm
PDF
Arrays-Computer programming
PDF
Array&amp;string
PDF
Homework Assignment – Array Technical DocumentWrite a technical .pdf
PPTX
One dimensional arrays
PPTX
array-160309152651.pptx
PDF
Array
PPT
Lec 25 - arrays-strings
PDF
Module7
PDF
Introduction to Arrays in C
PPTX
5 ARRAYS AND STRINGSjiuojhiooioiiouioi.pptx
PPTX
Module_3_Arrays - Updated.pptx............
Arrays
Arrays and library functions
Arrays
unit 2.pptx
arrayy.ppt
Array in C
Arrays in C language
ARRAYS.pptx
Arrays in Data Structure and Algorithm
Arrays-Computer programming
Array&amp;string
Homework Assignment – Array Technical DocumentWrite a technical .pdf
One dimensional arrays
array-160309152651.pptx
Array
Lec 25 - arrays-strings
Module7
Introduction to Arrays in C
5 ARRAYS AND STRINGSjiuojhiooioiiouioi.pptx
Module_3_Arrays - Updated.pptx............

More from eShikshak (14)

PDF
Modelling and evaluation
PDF
Operators in python
PDF
Datatypes in python
PDF
Introduction to python
PPT
Introduction to e commerce
PDF
Chapeter 2 introduction to cloud computing
PPT
Mesics lecture 7 iteration and repetitive executions
PPT
Mesics lecture 6 control statement = if -else if__else
PPT
Mesics lecture 4 c operators and experssions
PPT
Mesics lecture 5 input – output in ‘c’
PDF
Lecture20 user definedfunctions.ppt
PDF
Lecture18 structurein c.ppt
PDF
Lecture13 control statementswitch.ppt
PDF
Language processors
Modelling and evaluation
Operators in python
Datatypes in python
Introduction to python
Introduction to e commerce
Chapeter 2 introduction to cloud computing
Mesics lecture 7 iteration and repetitive executions
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 4 c operators and experssions
Mesics lecture 5 input – output in ‘c’
Lecture20 user definedfunctions.ppt
Lecture18 structurein c.ppt
Lecture13 control statementswitch.ppt
Language processors

Recently uploaded (20)

PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Complications of Minimal Access Surgery at WLH
PDF
Yogi Goddess Pres Conference Studio Updates
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
Classroom Observation Tools for Teachers
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
01-Introduction-to-Information-Management.pdf
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Anesthesia in Laparoscopic Surgery in India
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
VCE English Exam - Section C Student Revision Booklet
FourierSeries-QuestionsWithAnswers(Part-A).pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Microbial diseases, their pathogenesis and prophylaxis
Complications of Minimal Access Surgery at WLH
Yogi Goddess Pres Conference Studio Updates
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Cell Structure & Organelles in detailed.
Classroom Observation Tools for Teachers
Chinmaya Tiranga quiz Grand Finale.pdf
A systematic review of self-coping strategies used by university students to ...
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
01-Introduction-to-Information-Management.pdf
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
O7-L3 Supply Chain Operations - ICLT Program
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Anesthesia in Laparoscopic Surgery in India

Mesics lecture 8 arrays in 'c'

  • 1. A R R A Y Prakash Khaire Prakash Khaire The Mandvi Education Society Institute of Computer Science The Mandvi Education Society Institute of Computer Science S
  • 2. • It is derived data type. • An array is a very popular and useful data structure used to store data elements in successive memory locations. • It is known as “Composite data structure” as more than one element is stored in a sequence. • It permits only homogenous data. • An array can be declared of any standard or custom data type.
  • 3. • The array of character(strings) type works somewhat differently from an array of integers, floating numbers. • Array elements can be accessed by its position in the array called as index. • Values in an array are identified using array name with subscripts. • It is also known as subscripted variable.
  • 4. • The array can be done as under int a[5] = {1, 2, 3, 4, 5}; Calling array elements a[0] Refers to 1st element i.e. 1 a[1] Refers to 2nd element i.e. 2 a[2] Refers to 3rd element i.e. 3 a[3] Refers to 4th element i.e. 4 a[4] Refers to 5th element i.e. 5
  • 5. Size: Number of elements or capacity to store elements in an array is called its size. It is always mentioned in brackets “[ ]”. Type : Type refers to data type. It decides which type of element is stored in the array. It also instructs the compiler to reserve memory according to data type. Base : The address of the first element(0th) is a base address. The array name itself stores address of the first element. Index : The array name is used to refer to the array element. For example, num[x], num is array name and x is index. The value of x begins from 0 to onwards depending on the size of the array. The index value is always an integer value. Range : Index of an array i.e. value of x varies from lower bound to upper bound while writing or reading elements from an array. For example in num[100] the range of index is 0 to 99. Word : It indicates the space required for an element. In each memory location, computer can store a data piece. The space occupation varies from machine from machine to machine. If the size of element is more than word (one byte) then it occupies two successive memory locations. The variable of data type int, float, long need more than one byte in memory.
  • 6. 1. The Declaration int a[5] is the creation of five variables of integer types in memory. Instead of declaring five variables for five values, the programmer. 2. All the elements of an array share the same name, and they are distinguished from one another with the help of the element number. 3. The element number in an array plays a major role for calling each element. 4. Any particular element of an array can be modified separately without disturbing the other elements. int a[5] = {1, 2, 3, 4, 5} 5. Any element of an array a[] can be assigned/equated to another ordinary variable or array variable of its type.
  • 7. 6. An array elements are stored in contiguous memory 0 1 2 3 4 10 20 30 40 50 1000 1002 1004 1006 1008 7. Once the array is declared, its lowest boundary cannot be changed but upper boundary can be expanded. 8. We know that an array name itself is a pointer. Though it is a pointer, it does not need ‘*’ operator. The brackets “[]” automatically denote that the variable is a pointer. 9. All the elements of an array share the same near, and they are distinguished from one another with the help of the element number. 10. The amount of memory required for an array depends upon the data type and the number of elements. The total size in bytes for a single dimensional array is compared as shown below. Total bytes = sizeof(data type) x size of array
  • 8. 11. The operations such as insertion, deletion of an element can be done with list but cannot be done with an array. Once an array is created we cannot remove or insert memory location. An element can be deleted, replaced but the memory location remains as it is. 12. When an array is declared and not initialization, it contains garbage values. If we declared an array as static, all elements are initialized to zero.
  • 10. • A collections of variables are given one variable name using only one subscript and such a variable is called a single-subscripted variable or one dimensional array. • Syntax data_type ArrayName[size]; data_type : is a valid data type like int, float or char Arrayname : is a valid identifier size : maximum number of elements that can be stored in array
  • 11. • Initialization of an array – int a[5] – Type of array variable is “integer”. – Its variable name is a. – 5 is the size of the array. • The elements of an array are stored in contiguous memory locations. Element a[0] a[1] a[2] a[3] a[4] Value 5 4 6 3 7 Address 2050 2052 2054 2056 2058
  • 12.  Array index starts with zero  The last index in an array is num – 1 where num is the no of elements in a array  int a[9] is an array that stores 9 integers index 0 1 2 3 4 5 6 7 8 elements Memory address 100 102 104 106 108 110 112 114 116
  • 13. • An elements of an array must be initialized, otherwise they may contain “garbage” value. • An array can be initialized at either of the following stages – At compile time – At run time
  • 14. • We can initialize the elements of arrays in the same way as the ordinary variables when they are declared. type array_name[size] = {list of values}; • For example, int number[3] = {5,10,15}; float total[5] ={0.0, 15.75, -10.9}; • The size may be omitted. In such cases, the compiler allocates enough space for all initialized elements. int counter[] = {1,1,1,1}; • The character array may be initialized in the similar manner char name[] = {‘v’,’i’,’k’,’a’,’s’,’0’}; or char name[] = “vikas”;
  • 15. • An array can be explicitly initialized at run time. void main() { int MyArray[5],i; for(i=0;i<5;i++) { MyArray[i] = i * 10; } getch(); }
  • 16. • There could be situations where a table of values will have to be stored. Name/Marks Science Maths English Dhrumit 45 48 42 Uzer 48 44 44 Prakash 20 14 2 • C allows us to define such tables of items by using two- dimensional arrays. • The two dimensional array are declared as follows type array_name[row_size][column_size];
  • 17. int MyArray[3][3]; 0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2 0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2
  • 18. int MyArray[3][3] = {0,0,0,1,1,1,2,2,2}; int MyArray[3][3] = {{0,0,0},{1,1,1},{2,2,2}}; int MyArray[][] = { {0,0,0}, {1,1,1}, {2,2,2} }
  • 19. int MyArray[2][3] = {{1,1}, {2}}; In above, the remaining elements will be initialized to zero. int MyArray[3][5] = {{0},{0},{0}}; When all the elements are to be initialized to zero, the above statement can be used. int MyArray[][] = {0,0}; The first two elements will be initialized explicitly while the other elements will be initialized implicitly to zero.
  • 20. int MyArray[2][3] = {{1,1}, {2}}; In above, the remaining elements will be initialized to zero. int MyArray[3][5] = {{0},{0},{0}}; When all the elements are to be initialized to zero, the above statement can be used. int MyArray[][] = {0,0}; The first two elements will be initialized explicitly while the other elements will be initialized implicitly to zero.
  • 21. • C allows arrays of three or more dimensions. The exact limit is determined by the compiler. • The general form of a multi-dimensional array type array_name[s1][s2][s3]…[sm]; • Where si is the size of ith dimension. • For exmaple int MyArray[2][3][4];
  • 22. 0,0 0,1 0, 2 0,3 1,0 1,1 1,2 1,3 0,0 0,1 0,2 0,3 1,0 1,1 1,2 1,3 2,0 2,1 2,2 2,3