LectureTwenty - Lecture 20 Pointers – Part II By Ghada...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lecture 20 Pointers – Part II By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department The Hashemite University ٢ Outline ¡ sizeof Operator and Arrays. ¡ sizeof Operator and Pointers. ¡ Bubble Sort Using Call-by-reference. ¡ Pointer Expressions and Pointer Arithmetic. ¡ The Relationship Between Pointers and Arrays. The Hashemite University ٣ sizeof Operator and Arrays ¡ sizeof ¡ Returns size of operand in bytes ¡ Returns the result of type size_t which is unsigned integer. ¡ For arrays, sizeof returns ( the size of 1 element ) * ( number of elements ) ¡ if sizeof( int ) = 4 , then int myArray[10]; cout << sizeof(myArray); will print 40 ¡ To get the size of an array (number of elements) using sizeof operator do the following: Array size = sizeof(myArray)/ sizeof(int); The Hashemite University ٤ sizeof Operator and Pointers ¡ Applying sizeof operator for a pointer always returns a result of 4 regardless of the data type to which the pointer is pointing. The Hashemite University ٥ Bubble Sort Using Call-by- reference ¡ We will implement bubblesort function using pointers ¡ swap function must receive the address (using & ) of the array elements ¡ array elements have call-by-value default ¡ Using pointers and the * operator, swap is able to switch the values of the actual array elements ¡ Psuedocode Initialize array print data in original order Call function bubblesort print sorted array Define bubblesort The Hashemite University ٦ 1 // Fig. 5.15: fig05_15.cpp 2 // This program puts values into an array, sorts the values into 3 // ascending order, and prints the resulting array....
View Full Document

Page1 / 17

LectureTwenty - Lecture 20 Pointers – Part II By Ghada...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online