1 / 12

contact..

contact. website: http://www.t3houd.wordpress.com/cs220 email: t3houd@gmail.com twitter:@TA_Ohoud. Grades. 2 Quizzes(10 grade).. Quiz#1: Tuesday 28/5/1437 Quiz#2: Tuesday 27/6/1437 sheets+evaluation+attendance (10 grade). Array.

matildam
Télécharger la présentation

contact..

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. contact.. • website:http://www.t3houd.wordpress.com/cs220 • email:t3houd@gmail.com • twitter:@TA_Ohoud

  2. Grades • 2 Quizzes(10 grade).. • Quiz#1: Tuesday 28/5/1437 • Quiz#2: Tuesday 27/6/1437 • sheets+evaluation+attendance (10 grade)

  3. Array • An array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier.

  4. The declaration of arrays follows this syntax: • type name [elements]; • the foo array, with five elements of type int, can be declared as: int foo [5];

  5. Initializing arrays • But the elements in an array can be explicitly initialized to specific values when it is declared, by enclosing those initial values in braces {}. • For example: int foo [5] = { 16, 2, 77, 40, 12071 }; This statement declares an array that can be represented like this: int bar [5] = { 10, 20, 30 };

  6. The initializer can even have no values, just the braces: int baz [5] = { }; This creates an array of five int values, each initialized with a value of zero:

  7. Accessing the values of an array name[index] foo [2] = 75; x = foo[2]; int foo[5]; // declaration of a new array foo[2] = 75; // access to an element of the array. foo[0] = a; foo[a] = 75; b = foo [a+2]; foo[foo[a]] = foo[2] + 5;

  8. // arrays example #include <iostream> usingnamespace std; int foo [] = {16, 2, 77, 40, 12071}; int n, result=0; int main () { for ( n=0 ; n<5 ; ++n ) { result += foo[n]; } cout << result; return 0; } Answer: 12206

  9. Multidimensional arrays Multidimensional arrays can be described as "arrays of arrays". For example, a bi-dimensional array can be imagined as a two-dimensional table made of elements, all of them of a same uniform data type. • jimmy represents a bi-dimensional array of 3 per 5 elements of type int. The C++ syntax for this is: int jimmy [3][5];

  10. and, for example, the way to reference the second element vertically and fourth horizontally in an expression would be: jimmy[1][3];

  11. example: #define WIDTH 5 and HEIGHT 3 int WIDTH=5 , HEIGHT=3; int jimmy [HEIGHT][WIDTH]; int n,m; int main () { for (n=0; n<HEIGHT; n++) for (m=0; m<WIDTH; m++) { jimmy[n][m]=(n+1)*(m+1); } }

More Related