2. 2Rushdi Shams, Dept of CSE, KUET, Bangladesh
Passing Array Elements to FunctionsPassing Array Elements to Functions
Array elements can be passed to a function byArray elements can be passed to a function by
calling the function by value, or by referencecalling the function by value, or by reference
In the call by value we pass values of arrayIn the call by value we pass values of array
elements to the functionelements to the function
in the call by reference we pass addresses ofin the call by reference we pass addresses of
array elements to the functionarray elements to the function
3. 3Rushdi Shams, Dept of CSE, KUET, Bangladesh
Passing Array Elements toPassing Array Elements to
Functions: Call by valueFunctions: Call by value
4. 4Rushdi Shams, Dept of CSE, KUET, Bangladesh
Passing Array Elements toPassing Array Elements to
Functions: Call by referenceFunctions: Call by reference
6. 6Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointer ArithmeticPointer Arithmetic
Addition of a number to a pointerAddition of a number to a pointer
7. 7Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointer ArithmeticPointer Arithmetic
Subtraction of a number from a pointerSubtraction of a number from a pointer
8. 8Rushdi Shams, Dept of CSE, KUET, Bangladesh
What do we know so far?What do we know so far?
Array elements are always stored in contiguousArray elements are always stored in contiguous
memory locations.memory locations.
A pointer when incremented always points to anA pointer when incremented always points to an
immediately next location of its type.immediately next location of its type.
9. 9Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointers and ArraysPointers and Arrays
10. 10Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointer and ArrayPointer and Array
Our next two programs show ways in which weOur next two programs show ways in which we
can access the elements of this array.can access the elements of this array.
11. 11Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointer and ArrayPointer and Array
12. 12Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointer and ArrayPointer and Array
13. 13Rushdi Shams, Dept of CSE, KUET, Bangladesh
Passing entire array to functionPassing entire array to function
14. 14Rushdi Shams, Dept of CSE, KUET, Bangladesh
Similar Statements!Similar Statements!
15. 15Rushdi Shams, Dept of CSE, KUET, Bangladesh
Array of PointersArray of Pointers
The way there can be an array ofThe way there can be an array of intints or an arrays or an array
ofof floatfloats, similarly there can be an array ofs, similarly there can be an array of
pointerspointers
an array of pointers would be nothing but aan array of pointers would be nothing but a
collection of addressescollection of addresses
16. 16Rushdi Shams, Dept of CSE, KUET, Bangladesh
Array of pointersArray of pointers
17. 17Rushdi Shams, Dept of CSE, KUET, Bangladesh
Array of pointersArray of pointers
18. 18Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointers to arrayPointers to array
An array of pointers can even contain the addressesAn array of pointers can even contain the addresses
of other arraysof other arrays