SlideShare ist ein Scribd-Unternehmen logo
1 von 8
1
Md. Masuduzzaman (Prince)
Lecturer
American International University-Bangladesh
(AIUB)
 Arrays
 Structures of related data items
 Static entity (same size throughout program)
 A few types
 Pointer-based arrays (C-like)
 Arrays as objects (C++)
2
 Array
 Consecutive group of memory locations
 Same name and type (int, char, etc.)
 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
 Array elements 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
5
c[6]
-45
6
0
72
1543
-89
0
62
-3
1
6453
78
Name of array (Note
that all elements of
this array have the
same name, c)
c[0]
c[1]
c[2]
c[3]
c[11]
c[10]
c[9]
c[8]
c[7]
c[5]
c[4]
Position number of the
element within array c
 
 When declaring arrays, specify
 Name
 Type of array
 Any data type
 Number of elements
 type arrayName[ arraySize ];
int c[ 10 ]; // array of 10 integers
float d[ 3284 ]; // array of 3284 floats
 Declaring multiple arrays of same type
 Use comma separated list, like regular variables
int b[ 100 ], x[ 27 ];
6
 Initializing arrays
 For loop
 Set each element
 Initializer list
 Specify each element when array declared
int n[ 5 ] = { 1, 2, 3, 4, 5 };
 If not enough initializers, rightmost elements 0
 If too many syntax error
 To set every element to same value
int n[ 5 ] = { 0 };
 If array size omitted, initializers determine size
int n[] = { 1, 2, 3, 4, 5 };
 5 initializers, therefore 5 element array
7
8

Weitere Àhnliche Inhalte

Was ist angesagt?

Presentation on array
Presentation on array Presentation on array
Presentation on array
topu93
 

Was ist angesagt? (20)

Array in C
Array in CArray in C
Array in C
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Arrays Basics
Arrays BasicsArrays Basics
Arrays Basics
 
Basic array in c programming
Basic array in c programmingBasic array in c programming
Basic array in c programming
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
 
Arrays In C Language
Arrays In C LanguageArrays In C Language
Arrays In C Language
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
 
Array in c++
Array in c++Array in c++
Array in c++
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Array in c
Array in cArray in c
Array in c
 
Array in c language
Array in c language Array in c language
Array 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
 
Array c programming
Array c programmingArray c programming
Array c programming
 
Chap 7(array)
Chap 7(array)Chap 7(array)
Chap 7(array)
 
Array
ArrayArray
Array
 
Array
ArrayArray
Array
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
 
Arrays In C
Arrays In CArrays In C
Arrays In C
 

Ähnlich wie 7.basic array

array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
HEMAHEMS5
 
Programming in c arrays
Programming in c   arraysProgramming in c   arrays
Programming in c arrays
Uma mohan
 
arrays in c# including Classes handling arrays
arrays in c#  including Classes handling arraysarrays in c#  including Classes handling arrays
arrays in c# including Classes handling arrays
JayanthiM19
 

Ähnlich wie 7.basic array (20)

Lecture 2.8 Arrays.pdf
Lecture 2.8 Arrays.pdfLecture 2.8 Arrays.pdf
Lecture 2.8 Arrays.pdf
 
Arrays
ArraysArrays
Arrays
 
Lecture 15 - Array
Lecture 15 - ArrayLecture 15 - Array
Lecture 15 - Array
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
Data structure array
Data structure  arrayData structure  array
Data structure array
 
ARRAYS
ARRAYSARRAYS
ARRAYS
 
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
 
Chapter 4 (Part I) - Array and Strings.pdf
Chapter 4 (Part I) - Array and Strings.pdfChapter 4 (Part I) - Array and Strings.pdf
Chapter 4 (Part I) - Array and Strings.pdf
 
Arrays
ArraysArrays
Arrays
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
Programming in c arrays
Programming in c   arraysProgramming in c   arrays
Programming in c arrays
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
arrays in c# including Classes handling arrays
arrays in c#  including Classes handling arraysarrays in c#  including Classes handling arrays
arrays in c# including Classes handling arrays
 
Introduction to Array & Structure & Basic Algorithms.pptx
Introduction to Array & Structure & Basic Algorithms.pptxIntroduction to Array & Structure & Basic Algorithms.pptx
Introduction to Array & Structure & Basic Algorithms.pptx
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 

KĂŒrzlich hochgeladen

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

KĂŒrzlich hochgeladen (20)

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 

7.basic array

  • 1. 1 Md. Masuduzzaman (Prince) Lecturer American International University-Bangladesh (AIUB)
  • 2.  Arrays  Structures of related data items  Static entity (same size throughout program)  A few types  Pointer-based arrays (C-like)  Arrays as objects (C++) 2
  • 3.  Array  Consecutive group of memory locations  Same name and type (int, char, etc.)  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
  • 4.  Array elements 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
  • 5. 5 c[6] -45 6 0 72 1543 -89 0 62 -3 1 6453 78 Name of array (Note that all elements of this array have the same name, c) c[0] c[1] c[2] c[3] c[11] c[10] c[9] c[8] c[7] c[5] c[4] Position number of the element within array c  
  • 6.  When declaring arrays, specify  Name  Type of array  Any data type  Number of elements  type arrayName[ arraySize ]; int c[ 10 ]; // array of 10 integers float d[ 3284 ]; // array of 3284 floats  Declaring multiple arrays of same type  Use comma separated list, like regular variables int b[ 100 ], x[ 27 ]; 6
  • 7.  Initializing arrays  For loop  Set each element  Initializer list  Specify each element when array declared int n[ 5 ] = { 1, 2, 3, 4, 5 };  If not enough initializers, rightmost elements 0  If too many syntax error  To set every element to same value int n[ 5 ] = { 0 };  If array size omitted, initializers determine size int n[] = { 1, 2, 3, 4, 5 };  5 initializers, therefore 5 element array 7
  • 8. 8