CSCI 240 - Quiz Questions - Quiz 9

1. (4) Write a function that can directly alter the value of a character variable.   If the character is a letter ('a' to 'z' or 'A' to 'Z') then make the letter become the next letter ('a' becomes 'b' etc.).  If the letter is 'z' or 'Z' make it become the next higher ASCII value.  If the character is not a letter, don't alter it.  You may use either of the two techniques covered in class (and the lecture notes) to do this.

2. (2) Write a calling statement for the function you wrote above, passing it an argument so that the char variable ch is (potentially) altered.

3. (2) Write a calling statement for the function you wrote above, passing to it the 2nd character in a char array called chAr.  (By second, I mean the sub-oneth).

(Questions 4 and 5) Given the following:

double pi = 3.14159;
double *piPtr = π

Assume that pi is stored ad address 200 and piPtr is stored at address 400.

4. (2) What is the value of *piPtr?

 

5. (2) What is the value of piPtr? (in words)

 

For questions 6 and 7: Given the following function header:

void fn(int *n)

6. (2) Write an instruction (in the function body) to store 10 into the caller's variable referred to by n

7. (2) Suppose the caller wanted to pass

int i;

to the function fn() so that i could be altered by the function.  Write the calling statement.

For questions 8 - 11, assume that j is stored at location 2000.  More than one answer may be correct.  Circle all that are correct.

int j = 10;
int *ptr;
ptr = &j;

8. (2) What is stored at location 2000?
a. the address of j
b. ptr
c. 2000
d. 10

9. (2) What is stored in ptr?
a. 10
b. the address of ptr
c. the address of j
d. the value of j
e. 2000

10. (2) What will display if we execute

cout << j << ", " << *ptr;

a. 10, 10
b. 10, 2000
c. 2000, 10
d. 10, ptr

11. (2) Suppose we want to allow a function to alter the value stored in j.  How would we pass an argument so this could happen?  (More than 1 may be true.)
a. supply j as the argument
b. supply ptr as the argument
c. supply &ptr as the argument
d. supply &j as the argument

12. (2) If we pass an array as an argument, why don't we need the & in front of the array name?