hw - * symbol before each instance where we are comparing...

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

View Full Document Right Arrow Icon
Project 6—Computer Science 31 Ahmad El-Arabi 1. a) b) Within the function’s parameters, the pointer p is not passed by reference. In turn, when executing the findDisorder function inside the main function, the pointer ptr does not follow the pointer p. So when we try to access the pointer ptr it is no longer pointing to any specific memory location, but is an empty pointer. c) Once again this is a similar problem to what was encountered in part (b). Since we want to have the pointer p contain the value of the hypotenuse, it should be passed by reference to the function. But, in this case, we are not allowed to
Background image of page 1

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

View Full DocumentRight Arrow Icon
modify the function, but can only modify the main function. So to get around this problem, we make the pointer into a plain double and then pass the address of this double. Therefore the actual double value is changed. d) The main problem in the implementation of this program is that we are trying to compare the pointer addresses to character values. To fix this we must add the
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: * symbol before each instance where we are comparing the pointers value to the character values. e) The reason that this program does not print out what it is expected to print is because we are trying to access a memory location that points to nothing. When we pass arr (memory location of the beginning of the array) back to the main function, and we try to access this memory location, we get undefined behavior. The reason being that the array arr no longer exists once we leave the computeSquares function. Once this array is erased from memory, the memory location which was originally pointing to the array will now be pointing to some obscure value in memory. 2. a) b) c) d) e) f) g) h) i) j) 3. a) b) c) 4. The program prints the following, and the reason why is placed in comments. Output: 5. The function is as follows:...
View Full Document

Page1 / 5

hw - * symbol before each instance where we are comparing...

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

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