Project 6 Solution

Project 6 Solution - Spring 2009 CS 31 Project 6 Solutions...

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

View Full Document Right Arrow Icon
Spring 2009 CS 31 Project 6 Solutions First, because of the operators' order of precedence, the expression *ptr + 1 = 20 means (*ptr) + 1 = 20 . The expression (*ptr) + 1 evaluates to the int 11, not an int variable that can be assigned to. When corrected to *(ptr+1) = 20 , the expression means , which means arr[1] = 20 . . Second, the while loop doesn't access arr[2] and tries to access arr[-1] . One possible fix is . ptr++; while (ptr > arr) { ptr--; cout << ' ' << *ptr; // print values } findDisorder puts the correct value in p , but p is a copy of the caller's variable ptr , so findDisorder has no effect on ptr . The parameter p must be passed by reference, not by value: void findDisorder(int arr[], int n, int* p) The declaration double* p; declares p to be a pointer to double, but leaves it uninitialized — it does not point to any particular double. That uninitialized pointer is copied into the parameter resultPtr . In the expression *resultPtr = sqrt(…) , the attempt to dereference the uninitialized
Background image of page 1

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

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

This note was uploaded on 11/07/2009 for the course CS 31 taught by Professor Melkanoff during the Spring '00 term at UCLA.

Page1 / 4

Project 6 Solution - Spring 2009 CS 31 Project 6 Solutions...

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

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