EE1102 Introduction To Computer Programming: Multi-Dimensional Arrays
EE1102 Introduction To Computer Programming: Multi-Dimensional Arrays
Introduction to Computer
Programming
Multi-Dimensional Arrays
…0123456789abcdefghijABCDEFGHIJ9876543210…
Address(multi+1) = address(multi) + 10
Because the character array has 10 columns
Each of these is a pointer to a pointer (or pointer to a 1-D
array)
EE1102 Intro to Comp Prog 10
Revisiting Functions on Arrays
• Initializing a 2-dimensional array
0 0
1 1
2 2
3 3
0 1
EE1102 Intro to Comp Prog 14
Two Dimensional Arrays
• Declaration: int A[4][3] : 4 rows and
3 columns, 43 array
• Elements: A[i][j] - element in row i A[4][3]
and column j of array A 0 1 2
• Initialization: 3
int B[2][3]={{4,5,6},{0,3,5}};
EE1102 Intro to Comp Prog 15
Functions
• Break large computing tasks into small ones
• Transfer of control is affected by calling a function
– With a function call, we pass some parameters
– These parameters are used within the function
– A value is computed
– The value is returned to the function which initiated the
call
– A function could call itself, these are called recursive
function calls
• Function prototype, function definition, and
function call
EE1102 Intro to Comp Prog 16
Passing Arguments to Functions
• In C, function arguments are passed “by value”
– values of the arguments given to the called function
in temporary variables rather than the originals
– the modifications to the parameter variables do not
affect the variables in the calling function
• “Call by reference”
– variables are passed by reference
• subject to modification by the function
– achieved by passing the “address of” variables
• Selection sort i
• Insertion sort i