Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Programming Chapter 10: Array in Functions

Similar presentations


Presentation on theme: "Computer Programming Chapter 10: Array in Functions"— Presentation transcript:

1 Computer Programming Chapter 10: Array in Functions
by Mohd Jamil Mohamed Mokhtarudin Faculty of Mechanical Engineering

2 Chapter Description Aims Expected Outcomes To use array in functions
Know to transfer array to functions

3 Using arrays in standard functions
printf() and scanf() Example: printf(“Value of %d”, A[i]); Not: printf(“Value of %d”, A); You must specify which element to print, one by one Same with scanf: scanf(“%d”, &A[i]);

4 Only element array[2]=3 is passed
Arrays in Function Example 1: Passing Single element of an array to function Function: int function_name (int array); Passing single element: int array[] = {1,2,3,4}; int function_name (array[2]); Only element array[2]=3 is passed

5 Example 1

6 All elements in array are passed
Arrays in Function Example 2: Passing 1D array to function Function: int function_name (int array[]); Passing 1D array: int array[] = {1,2,3,4}; int function_name (array); All elements in array are passed

7 Example 2

8 All elements in 2D array are passed
Arrays in Function Example 3: Passing 2D array to function Function: int function_name (int array[][]); Passing 2D array: int array[][] = {{1,2},{3,4}}; int function_name (array); All elements in 2D array are passed

9 Example 3

10 Conclusion of The Chapter
Now you know how to transfer array variables into function Its time for final project!


Download ppt "Computer Programming Chapter 10: Array in Functions"

Similar presentations


Ads by Google