SlideShare ist ein Scribd-Unternehmen logo
1 von 22
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.
• 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

Weitere ähnliche Inhalte

Was ist angesagt?

Array in c language
Array in c languageArray in c language
Array in c language
home
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
topu93
 

Was ist angesagt? (20)

Chap09
Chap09Chap09
Chap09
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
 
Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
 
Array in c programming
Array in c programmingArray in c programming
Array in c programming
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
Array in C
Array in CArray in C
Array in C
 
Arrays Basics
Arrays BasicsArrays Basics
Arrays Basics
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
An Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: ArraysAn Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: Arrays
 
Array in c
Array in cArray in c
Array in c
 
Java arrays
Java arraysJava arrays
Java arrays
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
Array in C# 3.5
Array in C# 3.5Array in C# 3.5
Array in C# 3.5
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2
 
Arrays basics
Arrays basicsArrays basics
Arrays basics
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
 
A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 

Andere mochten auch

Lecture19 unionsin c.ppt
Lecture19 unionsin c.pptLecture19 unionsin c.ppt
Lecture19 unionsin c.ppt
eShikshak
 
Introduction to computer_and_its_structure
Introduction to computer_and_its_structureIntroduction to computer_and_its_structure
Introduction to computer_and_its_structure
eShikshak
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
eShikshak
 
Lecturer23 pointersin c.ppt
Lecturer23 pointersin c.pptLecturer23 pointersin c.ppt
Lecturer23 pointersin c.ppt
eShikshak
 
Lecture7relationalandlogicaloperators 110823181038-phpapp02
Lecture7relationalandlogicaloperators 110823181038-phpapp02Lecture7relationalandlogicaloperators 110823181038-phpapp02
Lecture7relationalandlogicaloperators 110823181038-phpapp02
eShikshak
 

Andere mochten auch (20)

Unit 1.3 types of cloud
Unit 1.3 types of cloudUnit 1.3 types of cloud
Unit 1.3 types of cloud
 
Unit 1.1 introduction to cloud computing
Unit 1.1   introduction to cloud computingUnit 1.1   introduction to cloud computing
Unit 1.1 introduction to cloud computing
 
Lecture19 unionsin c.ppt
Lecture19 unionsin c.pptLecture19 unionsin c.ppt
Lecture19 unionsin c.ppt
 
Unit 1.2 move to cloud computing
Unit 1.2   move to cloud computingUnit 1.2   move to cloud computing
Unit 1.2 move to cloud computing
 
Unit 1.4 working of cloud computing
Unit 1.4 working of cloud computingUnit 1.4 working of cloud computing
Unit 1.4 working of cloud computing
 
Lecture 12 css_fonts
Lecture 12 css_fontsLecture 12 css_fonts
Lecture 12 css_fonts
 
Introduction to computer_and_its_structure
Introduction to computer_and_its_structureIntroduction to computer_and_its_structure
Introduction to computer_and_its_structure
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
 
Lecture 11 css_inculsion
Lecture 11 css_inculsionLecture 11 css_inculsion
Lecture 11 css_inculsion
 
Program development cyle
Program development cyleProgram development cyle
Program development cyle
 
Lecturer23 pointersin c.ppt
Lecturer23 pointersin c.pptLecturer23 pointersin c.ppt
Lecturer23 pointersin c.ppt
 
Computer programming programming_langugages
Computer programming programming_langugagesComputer programming programming_langugages
Computer programming programming_langugages
 
Html phrase tags
Html phrase tagsHtml phrase tags
Html phrase tags
 
Lecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.pptLecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.ppt
 
Lecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.pptLecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.ppt
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
Mesics lecture 3 c – constants and variables
Mesics lecture 3   c – constants and variablesMesics lecture 3   c – constants and variables
Mesics lecture 3 c – constants and variables
 
Lecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operatorsLecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operators
 
Lecture7relationalandlogicaloperators 110823181038-phpapp02
Lecture7relationalandlogicaloperators 110823181038-phpapp02Lecture7relationalandlogicaloperators 110823181038-phpapp02
Lecture7relationalandlogicaloperators 110823181038-phpapp02
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'
 

Ähnlich wie Mesics lecture 8 arrays in 'c'

Programming fundamentals week 12.pptx
Programming fundamentals week 12.pptxProgramming fundamentals week 12.pptx
Programming fundamentals week 12.pptx
dfsdg3
 

Ähnlich wie Mesics lecture 8 arrays in 'c' (20)

Arrays
ArraysArrays
Arrays
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional
 
Arrays
ArraysArrays
Arrays
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
Arrays
ArraysArrays
Arrays
 
Chapter-Five.pptx
Chapter-Five.pptxChapter-Five.pptx
Chapter-Five.pptx
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
2 arrays
2   arrays2   arrays
2 arrays
 
Array 2 hina
Array 2 hina Array 2 hina
Array 2 hina
 
Arrays
ArraysArrays
Arrays
 
Programming fundamentals week 12.pptx
Programming fundamentals week 12.pptxProgramming fundamentals week 12.pptx
Programming fundamentals week 12.pptx
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
 
Arrays
ArraysArrays
Arrays
 
unit 2.pptx
unit 2.pptxunit 2.pptx
unit 2.pptx
 
Data structure array
Data structure  arrayData structure  array
Data structure array
 
Array and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdfArray and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdf
 
Arrays
ArraysArrays
Arrays
 

Mehr von eShikshak (14)

Modelling and evaluation
Modelling and evaluationModelling and evaluation
Modelling and evaluation
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introduction to e commerce
Introduction to e commerceIntroduction to e commerce
Introduction to e commerce
 
Chapeter 2 introduction to cloud computing
Chapeter 2   introduction to cloud computingChapeter 2   introduction to cloud computing
Chapeter 2 introduction to cloud computing
 
Mesics lecture 7 iteration and repetitive executions
Mesics lecture 7   iteration and repetitive executionsMesics lecture 7   iteration and repetitive executions
Mesics lecture 7 iteration and repetitive executions
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
 
Mesics lecture 4 c operators and experssions
Mesics lecture  4   c operators and experssionsMesics lecture  4   c operators and experssions
Mesics lecture 4 c operators and experssions
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
Lecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.pptLecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.ppt
 
Lecture18 structurein c.ppt
Lecture18 structurein c.pptLecture18 structurein c.ppt
Lecture18 structurein c.ppt
 
Lecture13 control statementswitch.ppt
Lecture13 control statementswitch.pptLecture13 control statementswitch.ppt
Lecture13 control statementswitch.ppt
 
Language processors
Language processorsLanguage processors
Language processors
 

Kürzlich hochgeladen

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 

Kürzlich hochgeladen (20)

General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 

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.
  • 9.
  • 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