SlideShare a Scribd company logo
1 of 8
Download to read offline
ARRAYS Lecture 2.8
Prepared by: Mian Saeed Akbar
Arrays
Array
 A collection of same datatype data, having a common name, a
unique index and are store in consecutive memory locations
To refer to an element
 Specify array name and position number (index)
 Format: arrayname[ position number ]
 First element at position 0
N-element array c
c[ 0 ], c[ 1 ] … c[ n - 1 ]
 Nth element as position N-1
Arrays
Array elements are treated like other variables
 Assignment, printing for an integer array c
c[ 0 ] = 3;
cout << c[ 0 ];
Can perform operations inside subscript
c[ 5 – 2 ] same as c[3]
Declaring Arrays
When declaring arrays, specify
 Name
 Type of array
 Any data type
 Number of elements
 type arrayName[ arraySize ];
Declaring multiple arrays of same type
 Use comma separated list, like regular variables
int c[ 10 ]; // array of 10 integers
float d[ 3284 ]; // array of 3284 floats
int b[ 100 ], x[ 27 ];
Initializing arrays
 For loop
 Set each element
 Initializer list
 Specify each element when array declared
 If not enough initializers, rightmost elements 0
 If too many syntax error
 To set every element to same value
 If array size omitted, initializers determine size
 5 initializers, therefore 5 element array
int n[ 5 ] = { 1, 2, 3, 4, 5 };
int n[ 5 ] = { 0 };
int n[] = { 1, 2, 3, 4, 5 };
Passing Arrays to Functions
Specify name without brackets
 To pass array myArray to myFunction
 Array size usually passed, but not required
 Useful to iterate over all elements
Arrays passed-by-reference
 Functions can modify original array data
 Value of name of array is address of first element
 Function knows where the array is stored
 Can change original memory locations
Individual array elements passed-by-value
 Like regular variables
int myArray[ 24 ];
myFunction( myArray, 24 );
square( myArray[3] );
Passing Arrays to Functions
Functions taking arrays
 Function prototype
 Names optional in prototype
 Both take an integer array and a single integer
 No need for array size between brackets
 Ignored by compiler
 If declare array parameter as const
 Cannot be modified (compiler error)
void modifyArray( int b[], int arraySize );
void modifyArray( int [], int );
void doNotModify( const int [] );
Thank you
Please subscribe my channel for more videos
and courses

More Related Content

Similar to Lecture 2.8 Arrays.pdf

Similar to Lecture 2.8 Arrays.pdf (20)

2D Array
2D Array 2D Array
2D Array
 
Arrays
ArraysArrays
Arrays
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technology
 
ARRAYS.ppt
ARRAYS.pptARRAYS.ppt
ARRAYS.ppt
 
Arrays in programming
Arrays in programmingArrays in programming
Arrays in programming
 
2 arrays
2   arrays2   arrays
2 arrays
 
Computer programming 2 Lesson 13
Computer programming 2  Lesson 13Computer programming 2  Lesson 13
Computer programming 2 Lesson 13
 
Array
ArrayArray
Array
 
Algo>Arrays
Algo>ArraysAlgo>Arrays
Algo>Arrays
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
ARRAYS.ppt
ARRAYS.pptARRAYS.ppt
ARRAYS.ppt
 
ARRAYS.ppt
ARRAYS.pptARRAYS.ppt
ARRAYS.ppt
 
Arrays are used to store multiple values in a single variable, instead of dec...
Arrays are used to store multiple values in a single variable, instead of dec...Arrays are used to store multiple values in a single variable, instead of dec...
Arrays are used to store multiple values in a single variable, instead of dec...
 
ARRAYS.ppt
ARRAYS.pptARRAYS.ppt
ARRAYS.ppt
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
Lecture 15 - Array
Lecture 15 - ArrayLecture 15 - Array
Lecture 15 - Array
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 

More from MianSaeedAkbar1

Lecture 1.3 A Simple Program to Print a Line of Text.pdf
Lecture 1.3 A Simple Program to Print a Line of Text.pdfLecture 1.3 A Simple Program to Print a Line of Text.pdf
Lecture 1.3 A Simple Program to Print a Line of Text.pdfMianSaeedAkbar1
 
Lecture 2.2 Default Arguments.pdf
Lecture 2.2 Default Arguments.pdfLecture 2.2 Default Arguments.pdf
Lecture 2.2 Default Arguments.pdfMianSaeedAkbar1
 
Lecture 2.6 Function Templates.pdf
Lecture 2.6 Function Templates.pdfLecture 2.6 Function Templates.pdf
Lecture 2.6 Function Templates.pdfMianSaeedAkbar1
 
Lecture 2.4 Recursion.pdf
Lecture 2.4 Recursion.pdfLecture 2.4 Recursion.pdf
Lecture 2.4 Recursion.pdfMianSaeedAkbar1
 
Lecture 3 Structures in C++.pdf
Lecture 3 Structures in C++.pdfLecture 3 Structures in C++.pdf
Lecture 3 Structures in C++.pdfMianSaeedAkbar1
 
Lecture 2.5 Function Overloading.pdf
Lecture 2.5 Function Overloading.pdfLecture 2.5 Function Overloading.pdf
Lecture 2.5 Function Overloading.pdfMianSaeedAkbar1
 
Lecture 1.11 Break and Continue Statements.pdf
Lecture 1.11 Break and Continue Statements.pdfLecture 1.11 Break and Continue Statements.pdf
Lecture 1.11 Break and Continue Statements.pdfMianSaeedAkbar1
 
Lecture 2.1 Functions.pdf
Lecture 2.1 Functions.pdfLecture 2.1 Functions.pdf
Lecture 2.1 Functions.pdfMianSaeedAkbar1
 
Lecture 1.5 Variables.pdf
Lecture 1.5 Variables.pdfLecture 1.5 Variables.pdf
Lecture 1.5 Variables.pdfMianSaeedAkbar1
 
Lecture 1.2 Basics of a typical C++ Environment.pdf
Lecture 1.2 Basics of a typical C++ Environment.pdfLecture 1.2 Basics of a typical C++ Environment.pdf
Lecture 1.2 Basics of a typical C++ Environment.pdfMianSaeedAkbar1
 
Lecture 2.3 Inline Function.pdf
Lecture 2.3 Inline Function.pdfLecture 2.3 Inline Function.pdf
Lecture 2.3 Inline Function.pdfMianSaeedAkbar1
 
Lecture 1.8 Conditional Structures.pdf
Lecture 1.8 Conditional Structures.pdfLecture 1.8 Conditional Structures.pdf
Lecture 1.8 Conditional Structures.pdfMianSaeedAkbar1
 
Lecture 2.7 Type Conversion in C++.pdf
Lecture 2.7 Type Conversion in C++.pdfLecture 2.7 Type Conversion in C++.pdf
Lecture 2.7 Type Conversion in C++.pdfMianSaeedAkbar1
 
Lecture 1.6 Arithmetic and Relational Operators.pdf
Lecture 1.6 Arithmetic and Relational Operators.pdfLecture 1.6 Arithmetic and Relational Operators.pdf
Lecture 1.6 Arithmetic and Relational Operators.pdfMianSaeedAkbar1
 
Lecture 1.7 C++ Keywords.pdf
Lecture 1.7 C++ Keywords.pdfLecture 1.7 C++ Keywords.pdf
Lecture 1.7 C++ Keywords.pdfMianSaeedAkbar1
 
Lecture 1.4 Escape Sequence.pdf
Lecture 1.4 Escape Sequence.pdfLecture 1.4 Escape Sequence.pdf
Lecture 1.4 Escape Sequence.pdfMianSaeedAkbar1
 
Lecture 1.9 Switch Structure.pdf
Lecture 1.9 Switch Structure.pdfLecture 1.9 Switch Structure.pdf
Lecture 1.9 Switch Structure.pdfMianSaeedAkbar1
 
Lecture 1.10 Repetition Structures.pdf
Lecture 1.10 Repetition Structures.pdfLecture 1.10 Repetition Structures.pdf
Lecture 1.10 Repetition Structures.pdfMianSaeedAkbar1
 
Lecture 0 Object Oriented Programming.pdf
Lecture 0 Object Oriented Programming.pdfLecture 0 Object Oriented Programming.pdf
Lecture 0 Object Oriented Programming.pdfMianSaeedAkbar1
 
Lecture 1.1 Introduction to Computer Languages.pdf
Lecture 1.1 Introduction to Computer Languages.pdfLecture 1.1 Introduction to Computer Languages.pdf
Lecture 1.1 Introduction to Computer Languages.pdfMianSaeedAkbar1
 

More from MianSaeedAkbar1 (20)

Lecture 1.3 A Simple Program to Print a Line of Text.pdf
Lecture 1.3 A Simple Program to Print a Line of Text.pdfLecture 1.3 A Simple Program to Print a Line of Text.pdf
Lecture 1.3 A Simple Program to Print a Line of Text.pdf
 
Lecture 2.2 Default Arguments.pdf
Lecture 2.2 Default Arguments.pdfLecture 2.2 Default Arguments.pdf
Lecture 2.2 Default Arguments.pdf
 
Lecture 2.6 Function Templates.pdf
Lecture 2.6 Function Templates.pdfLecture 2.6 Function Templates.pdf
Lecture 2.6 Function Templates.pdf
 
Lecture 2.4 Recursion.pdf
Lecture 2.4 Recursion.pdfLecture 2.4 Recursion.pdf
Lecture 2.4 Recursion.pdf
 
Lecture 3 Structures in C++.pdf
Lecture 3 Structures in C++.pdfLecture 3 Structures in C++.pdf
Lecture 3 Structures in C++.pdf
 
Lecture 2.5 Function Overloading.pdf
Lecture 2.5 Function Overloading.pdfLecture 2.5 Function Overloading.pdf
Lecture 2.5 Function Overloading.pdf
 
Lecture 1.11 Break and Continue Statements.pdf
Lecture 1.11 Break and Continue Statements.pdfLecture 1.11 Break and Continue Statements.pdf
Lecture 1.11 Break and Continue Statements.pdf
 
Lecture 2.1 Functions.pdf
Lecture 2.1 Functions.pdfLecture 2.1 Functions.pdf
Lecture 2.1 Functions.pdf
 
Lecture 1.5 Variables.pdf
Lecture 1.5 Variables.pdfLecture 1.5 Variables.pdf
Lecture 1.5 Variables.pdf
 
Lecture 1.2 Basics of a typical C++ Environment.pdf
Lecture 1.2 Basics of a typical C++ Environment.pdfLecture 1.2 Basics of a typical C++ Environment.pdf
Lecture 1.2 Basics of a typical C++ Environment.pdf
 
Lecture 2.3 Inline Function.pdf
Lecture 2.3 Inline Function.pdfLecture 2.3 Inline Function.pdf
Lecture 2.3 Inline Function.pdf
 
Lecture 1.8 Conditional Structures.pdf
Lecture 1.8 Conditional Structures.pdfLecture 1.8 Conditional Structures.pdf
Lecture 1.8 Conditional Structures.pdf
 
Lecture 2.7 Type Conversion in C++.pdf
Lecture 2.7 Type Conversion in C++.pdfLecture 2.7 Type Conversion in C++.pdf
Lecture 2.7 Type Conversion in C++.pdf
 
Lecture 1.6 Arithmetic and Relational Operators.pdf
Lecture 1.6 Arithmetic and Relational Operators.pdfLecture 1.6 Arithmetic and Relational Operators.pdf
Lecture 1.6 Arithmetic and Relational Operators.pdf
 
Lecture 1.7 C++ Keywords.pdf
Lecture 1.7 C++ Keywords.pdfLecture 1.7 C++ Keywords.pdf
Lecture 1.7 C++ Keywords.pdf
 
Lecture 1.4 Escape Sequence.pdf
Lecture 1.4 Escape Sequence.pdfLecture 1.4 Escape Sequence.pdf
Lecture 1.4 Escape Sequence.pdf
 
Lecture 1.9 Switch Structure.pdf
Lecture 1.9 Switch Structure.pdfLecture 1.9 Switch Structure.pdf
Lecture 1.9 Switch Structure.pdf
 
Lecture 1.10 Repetition Structures.pdf
Lecture 1.10 Repetition Structures.pdfLecture 1.10 Repetition Structures.pdf
Lecture 1.10 Repetition Structures.pdf
 
Lecture 0 Object Oriented Programming.pdf
Lecture 0 Object Oriented Programming.pdfLecture 0 Object Oriented Programming.pdf
Lecture 0 Object Oriented Programming.pdf
 
Lecture 1.1 Introduction to Computer Languages.pdf
Lecture 1.1 Introduction to Computer Languages.pdfLecture 1.1 Introduction to Computer Languages.pdf
Lecture 1.1 Introduction to Computer Languages.pdf
 

Recently uploaded

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
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 .pdfchloefrazer622
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
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).pdfSoniaTolstoy
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
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 GraphThiyagu K
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 

Recently uploaded (20)

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
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"
 
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
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
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
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
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
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 

Lecture 2.8 Arrays.pdf

  • 1. ARRAYS Lecture 2.8 Prepared by: Mian Saeed Akbar
  • 2. Arrays Array  A collection of same datatype data, having a common name, a unique index and are store in consecutive memory locations To refer to an element  Specify array name and position number (index)  Format: arrayname[ position number ]  First element at position 0 N-element array c c[ 0 ], c[ 1 ] … c[ n - 1 ]  Nth element as position N-1
  • 3. Arrays Array elements are treated like other variables  Assignment, printing for an integer array c c[ 0 ] = 3; cout << c[ 0 ]; Can perform operations inside subscript c[ 5 – 2 ] same as c[3]
  • 4. Declaring Arrays When declaring arrays, specify  Name  Type of array  Any data type  Number of elements  type arrayName[ arraySize ]; Declaring multiple arrays of same type  Use comma separated list, like regular variables int c[ 10 ]; // array of 10 integers float d[ 3284 ]; // array of 3284 floats int b[ 100 ], x[ 27 ];
  • 5. Initializing arrays  For loop  Set each element  Initializer list  Specify each element when array declared  If not enough initializers, rightmost elements 0  If too many syntax error  To set every element to same value  If array size omitted, initializers determine size  5 initializers, therefore 5 element array int n[ 5 ] = { 1, 2, 3, 4, 5 }; int n[ 5 ] = { 0 }; int n[] = { 1, 2, 3, 4, 5 };
  • 6. Passing Arrays to Functions Specify name without brackets  To pass array myArray to myFunction  Array size usually passed, but not required  Useful to iterate over all elements Arrays passed-by-reference  Functions can modify original array data  Value of name of array is address of first element  Function knows where the array is stored  Can change original memory locations Individual array elements passed-by-value  Like regular variables int myArray[ 24 ]; myFunction( myArray, 24 ); square( myArray[3] );
  • 7. Passing Arrays to Functions Functions taking arrays  Function prototype  Names optional in prototype  Both take an integer array and a single integer  No need for array size between brackets  Ignored by compiler  If declare array parameter as const  Cannot be modified (compiler error) void modifyArray( int b[], int arraySize ); void modifyArray( int [], int ); void doNotModify( const int [] );
  • 8. Thank you Please subscribe my channel for more videos and courses