SlideServe
Menu
Préférences
© SlideServe · v2026

Engineering 1020

sumana avatar
10 diapositives · 274 Views · Oct 10, 2014

Engineering 1020. Introduction to Programming Peter King peter.king@mun.ca www.engr.mun.ca/~peter Winter 2010. ENGI 1020: Arrays. We've seen variables a data container of a certain type than holds a single value and is assigned a label Arrays are an extension of variables

Engineering 1020 - slide 1
01 / 10Engineering 1020
1 / 17

Télécharger la présentation

Engineering 1020
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Engineering 1020 Introduction to Programming Peter King peter.king@mun.ca www.engr.mun.ca/~peter Winter 2010

  2. ENGI 1020: Arrays We've seen variables a data container of a certain type than holds a single value and is assigned a label Arrays are an extension of variables a data container or a certain type that can hold many values and is assigned a label An array is a compound variable

  3. ENGI 1020: Arrays Like a variable: int a; Arrays are declared: int b[10]; Where, the number in the square brackets represents the number of values held by the array

  4. ENGI 1020: Arrays int c[10]; double x[22]; char letters[30]; c is an array of 10 integers. x is an array of 22 doubles letters is an array of 30 characters

  5. ENGI 1020: Arrays Think of arrays as a list of homogenous variables Each element is a variable of the type declared Each element can be accessed and changed (they are variable) The entire array resides in memory, which each element in a successive address

  6. ENGI 1020: Arrays Working with arrays: Initialization: int fib[10] = {1, 1, 2, 3, 5, 8, 13, 21, 34, 55};

  7. ENGI 1020: Arrays Element access: int fib[10] = {1, 1, 2, 3, 5, 8, 13, 21, 34, 55}; cout << “The first element is: “ << fib[0]; int sum = fib[1] + fib[3] + fib[7]; fib[5] = 12;

  8. ENGI 1020: Arrays IMPORTANT if you declare an array of size n int arry[n]; The elements are indexed 0 to n-1 int nums[9]; has no element 9, just 0,1,2,3,4,5,6,7,8

  9. ENGI 1020: Arrays The size of the array and indexes must be carefully managed Referencing an element outside of the array index is an error. Arrays can be a great way to pass around related data to functions

  10. ENGI 1020: Arrays Online examples using in functions search/sort operations Things you can't do with arrays