C-15
-
Upload
rushdi-shams -
Category
Education
-
view
89 -
download
0
description
Transcript of C-15
![Page 1: C-15](https://reader033.fdocuments.in/reader033/viewer/2022061221/54bd2e474a795927668b456b/html5/thumbnails/1.jpg)
Lecture 15Lecture 15Version 1.0Version 1.0
Pointers and ArraysPointers and Arrays
![Page 2: C-15](https://reader033.fdocuments.in/reader033/viewer/2022061221/54bd2e474a795927668b456b/html5/thumbnails/2.jpg)
2Rushdi Shams, Dept of CSE, KUET, Bangladesh
Passing Array Elements to Passing Array Elements to FunctionsFunctions
Array elements can be passed to a Array elements can be passed to a function by calling the function by function by calling the function by value, or by reference value, or by reference
In the call by value we pass values of In the call by value we pass values of array elements to the function array elements to the function
in the call by reference we pass in the call by reference we pass addresses of array elements to the addresses of array elements to the function function
![Page 3: C-15](https://reader033.fdocuments.in/reader033/viewer/2022061221/54bd2e474a795927668b456b/html5/thumbnails/3.jpg)
3Rushdi Shams, Dept of CSE, KUET, Bangladesh
Passing Array Elements to Passing Array Elements to Functions: Call by valueFunctions: Call by value
![Page 4: C-15](https://reader033.fdocuments.in/reader033/viewer/2022061221/54bd2e474a795927668b456b/html5/thumbnails/4.jpg)
4Rushdi Shams, Dept of CSE, KUET, Bangladesh
Passing Array Elements to Passing Array Elements to Functions: Call by referenceFunctions: Call by reference
![Page 5: C-15](https://reader033.fdocuments.in/reader033/viewer/2022061221/54bd2e474a795927668b456b/html5/thumbnails/5.jpg)
5Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointer ArithmeticPointer Arithmetic
![Page 6: C-15](https://reader033.fdocuments.in/reader033/viewer/2022061221/54bd2e474a795927668b456b/html5/thumbnails/6.jpg)
6Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointer ArithmeticPointer Arithmetic
Addition of a number to a pointer Addition of a number to a pointer
![Page 7: C-15](https://reader033.fdocuments.in/reader033/viewer/2022061221/54bd2e474a795927668b456b/html5/thumbnails/7.jpg)
7Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointer ArithmeticPointer Arithmetic
Subtraction of a number from a pointer Subtraction of a number from a pointer
![Page 8: C-15](https://reader033.fdocuments.in/reader033/viewer/2022061221/54bd2e474a795927668b456b/html5/thumbnails/8.jpg)
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 Array elements are always stored in contiguous memory locations. contiguous memory locations.
A pointer when incremented always A pointer when incremented always points to an immediately next points to an immediately next location of its type. location of its type.
![Page 9: C-15](https://reader033.fdocuments.in/reader033/viewer/2022061221/54bd2e474a795927668b456b/html5/thumbnails/9.jpg)
9Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointers and ArraysPointers and Arrays
![Page 10: C-15](https://reader033.fdocuments.in/reader033/viewer/2022061221/54bd2e474a795927668b456b/html5/thumbnails/10.jpg)
10Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointer and ArrayPointer and Array
Our next two programs show ways in Our next two programs show ways in which we can access the elements of which we can access the elements of this array. this array.
![Page 11: C-15](https://reader033.fdocuments.in/reader033/viewer/2022061221/54bd2e474a795927668b456b/html5/thumbnails/11.jpg)
11Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointer and ArrayPointer and Array
![Page 12: C-15](https://reader033.fdocuments.in/reader033/viewer/2022061221/54bd2e474a795927668b456b/html5/thumbnails/12.jpg)
12Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointer and ArrayPointer and Array
![Page 13: C-15](https://reader033.fdocuments.in/reader033/viewer/2022061221/54bd2e474a795927668b456b/html5/thumbnails/13.jpg)
13Rushdi Shams, Dept of CSE, KUET, Bangladesh
Passing entire array to Passing entire array to functionfunction
![Page 14: C-15](https://reader033.fdocuments.in/reader033/viewer/2022061221/54bd2e474a795927668b456b/html5/thumbnails/14.jpg)
14Rushdi Shams, Dept of CSE, KUET, Bangladesh
Similar Statements!Similar Statements!
![Page 15: C-15](https://reader033.fdocuments.in/reader033/viewer/2022061221/54bd2e474a795927668b456b/html5/thumbnails/15.jpg)
15Rushdi Shams, Dept of CSE, KUET, Bangladesh
Array of PointersArray of Pointers
The way there can be an array of The way there can be an array of intints or an array of s or an array of floatfloats, similarly s, similarly there can be an array of pointers there can be an array of pointers
an array of pointers would be an array of pointers would be nothing but a collection of addresses nothing but a collection of addresses
![Page 16: C-15](https://reader033.fdocuments.in/reader033/viewer/2022061221/54bd2e474a795927668b456b/html5/thumbnails/16.jpg)
16Rushdi Shams, Dept of CSE, KUET, Bangladesh
Array of pointersArray of pointers
![Page 17: C-15](https://reader033.fdocuments.in/reader033/viewer/2022061221/54bd2e474a795927668b456b/html5/thumbnails/17.jpg)
17Rushdi Shams, Dept of CSE, KUET, Bangladesh
Array of pointersArray of pointers
![Page 18: C-15](https://reader033.fdocuments.in/reader033/viewer/2022061221/54bd2e474a795927668b456b/html5/thumbnails/18.jpg)
18Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointers to arrayPointers to array
An array of pointers can even contain An array of pointers can even contain the addresses of other arrays the addresses of other arrays