C Lesson#6 (Fin)
C Lesson#6 (Fin)
Lesson 6:
Arrays
Prepared by:
Prof. Marienel N. Velasco
Unit
Pg. 1
I’m gonna talk about:
Unit
Pg. 2
Arrays
float marks[100];
2 Types of
1. One-dimensional arrays
Arrays:
2. Multidimensional arrays
For example,
float mark[5];
Here, we declared an array, mark of floating-point type and
size 5. Meaning, it can hold 5 floating-point values.
Unit
Pg. 4
Elements of an Array and How to access them?
Here,
mark[0] is equal to 19
mark[1] is equal to 10
mark[2] is equal to 8
mark[3] is equal to 17
mark[4] is equal to 9
Unit
Pg. 6
How to insert and print array elements?
Unit
Pg. 7
Example: C Arrays
Unit
Pg. 8
Important thing to remember when working with C arrays
Unit
Pg. 9
C Programming Multidimensional Arrays
float x[3][4];
• Here, x is a two-dimensional (2d) array. The array can hold 12
elements. You can think the array as table with 3 row and each
row has 4 column.
Unit
Pg. 10
C Programming Multidimensional Arrays
Unit
Pg. 11
How to initialize a multidimensional array?
Unit
Pg. 12
How to initialize a multidimensional array?
int test[2][3][4] = {
{ {3, 4, 2, 3}, {0, -3, 9, 11}, {23, 12, 23, 2} },
{13, 4, 56, 3}, {5, 9, 3, 5}, {3, 1, 4, 9} }
};
Unit
Pg. 13
Example1: Two Dimensional Array to store
and display values
Unit
Pg. 14
Example2: Sum of two matrices using Two
dimensional arrays
Unit
Pg. 16
Passing One-dimensional Array In Function
#include <stdio.h>
void display(int age)
{
printf("%d", age);
}
int main()
{
int ageArray[] = { 2, 3, 4 };
display(ageArray[2]); //Passing array element
ageArray[2] only.
return 0; }
Unit
Pg. 17
Passing an entire one-dimensional array to a
function
Unit
Pg. 18
Passing Multi-dimensional Arrays to Function
Unit
Pg. 20