Arrays in C Programming, Slides of Computer Science

Arrays in C Programming, introduction to the topic

Typology: Slides

2020/2021

Uploaded on 01/29/2022

renzo-santos-2
renzo-santos-2 🇵🇭

4

(1)

1 document

1 / 69

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Arrays
-
・フ
/* Read Chapter 1 of the Course Notes for details. */
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45

Partial preview of the text

Download Arrays in C Programming and more Slides Computer Science in PDF only on Docsity!

Arrays

サルバド - ル・フロランテ

/* Read Chapter 1 of the Course Notes for details. */

Visual Examples of Arrays 2 https://pixabay.com/vectors/chessboard-chess-board-game-29630/ https://en.wikipedia.org/wiki/Rubik%27s_Cube#/media/ File:Rubiks_cube_solved.jpg https://www.photos-public-domain.com/2011/08/30/truth/

Visual Examples of Arrays 4 https://pixabay.com/vectors/chessboard-chess-board-game-29630/ https://en.wikipedia.org/wiki/Rubik%27s_Cube#/media/ File:Rubiks_cube_solved.jpg https://www.photos-public-domain.com/2011/08/30/truth/ 2D array 8 rows by 8 columns = group of 64 squares

1 st^ row

8 th^ row

st

col 8 th^ col

Visual Examples of Arrays 5 https://pixabay.com/vectors/chessboard-chess-board-game-29630/ https://en.wikipedia.org/wiki/Rubik%27s_Cube#/media/ File:Rubiks_cube_solved.jpg https://www.photos-public-domain.com/2011/08/30/truth/

1 st^ row

8 th^ row

st

col 8 th^ col

3D array 3 (length) by 3 (width) by 3 (height) = group of 27 small cubes

Q: How do you declare an array in C?

  • 1D array // also called “list” [ ]
  • 2D array // also called “table”, “matrix” [ ][]
  • 3D array [ ][][] size must be a non- negative integer

Example: Array Declarations

// example 1D array declaration

char str[5]; int A[5], B[10]; float Grades[40]; double D[1000]; name : str dimensionality : 1D size : 5 element type : char

Example: Array Declarations

// example 1D array declaration

char str[5]; int A[5], B[10]; float Grades[40]; double D[1000];

// example 2D array declaration

char CrossWord[10][10]; // 10 rows x 10 columns int Sudoku[9][9]; float Table[2][4]; double Matrix[3][5];

// example 3D array declaration

int RubikCube[3][3][3]; name : RubikCube dimensionality : 3D size : 3x3x element type : int

Exercise: Declare array variables for the ff. https://pixabay.com/vectors/chessboard-chess-board-game-29630/ https://www.photos-public-domain.com/2011/08/30/truth/ https://en.wikipedia.org/wiki/Rubik%27s_Revenge# /media/File:Rubiks_revenge_solved.jpg https://www.goodfreephotos.com/other- photos/stack-of-flat-rocks.jpg.php

Q: How do you visualize/draw a 1D Array? Option 1: draw it vertically

Q: How do you visualize/draw a 1D Array? Option 2: or draw it horizontally

Q: How do you visualize/draw a 1D Array? Drawing an array of floating point values

Q: How do you access an array element? Declaration: int A[8];

Q: How do you access an array element? index is from 0 to size - 1 Declaration: int A[8];

Q: How do you access an array element? Access an element by giving the array name, and its index enclosed in [ ]. A[0] A[3] A[7] A[4] A[5] A[6] A[2] A[1] Declaration: int A[8];