0% found this document useful (0 votes)
49 views11 pages

Passing Arrays To Functions

This document discusses passing arrays to functions in C. There are two ways to pass an array to a function: 1) Pass each array element individually, known as "pass by value," where changes inside the function do not affect the original array. 2) Pass the entire array by passing its base address, known as "pass by reference," where any changes made inside the function are reflected in the original array. The document provides examples of passing both one-dimensional and multi-dimensional arrays to functions.

Uploaded by

Bharath Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views11 pages

Passing Arrays To Functions

This document discusses passing arrays to functions in C. There are two ways to pass an array to a function: 1) Pass each array element individually, known as "pass by value," where changes inside the function do not affect the original array. 2) Pass the entire array by passing its base address, known as "pass by reference," where any changes made inside the function are reflected in the original array. The document provides examples of passing both one-dimensional and multi-dimensional arrays to functions.

Uploaded by

Bharath Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

PASSING ARRAYS TO FUNCTIONS

Submitted by

VYSHAKH C B
19MSPHCP06
Msc.Computational Physics
ARRAY DEFINITION :
Array is a collection of variables belongings to the same data type. You can store
group of data of same data type in an array.
EXAMPLE FOR C ARRAYS:
● int a[10]; // integer array

● char b[10]; // character array i.e. string

TYPES OF C ARRAYS:
There are 2 types of C arrays. They are,

1. One dimensional array

2. Multi dimensional array


○ Two dimensional array
○ Three dimensional array
○ four dimensional array etc…
PASSING ARRAY TO FUNCTION :
Array can be passed to function by two ways :

a. Pass Array element by element

b. Pass Entire array


1 . PASS ARRAY ELEMENT BY ELEMENT
● Here individual elements are passed to function as argument.
● Duplicate carbon copy of Original variable is passed to
function .
● So any changes made inside function does not affects the
original value.
● Function doesn’t get complete access to the original array
element.
● Function passing method is “Pass by Value“
Passing a single array element to a function
Example 2. Passing a single array element to a function
1 . PASS ENTIRE ARRAY

● Here entire array can be passed as a argument to function .


● Function gets complete access to the original array .
● While passing entire array Address of first element is passed to function , any changes
made inside function , directly affects the Original value .
● Function Passing method : “Pass by Address“
● Parameter Passing Scheme : Pass by Reference
● Pass name of array as function parameter .
● Name contains the base address i.e ( Address of 0th element )
● Array values are updated in function .
● Values are reflected inside main function also
Passing a complete One-dimensional array to a function
Passing a Multi-dimensional array to a function
Example 2.Passing a Multi-dimensional array to a function
Thank you

You might also like