C++ Chapters GRADE A QUESTION AND
ANSWERS
&diff - (correct answer)Assume the variable diff has already been declared. Write an
expression whose value is the address of diff .
int *ip; - (correct answer)Declare a variable ip that can be assigned the address of an int
variable. In other words, declare ip to be of type "pointer to int ".
char *cp; - (correct answer)Declare a variable cp that can be assigned the address of an
char variable. In other words, declare cp to be of type "pointer to char ".
double *dp; - (correct answer)Declare a variable dp that can be assigned the address of
a double variable. In other words, declare dp to be of type "pointer to double ".
counterPointer = &counter; - (correct answer)Assume that an int variable counter has
already been declared. Assume further a variable counterPointer of type "pointer to int "
has also already been declared. Write a statement that makes counterPointer "point" to
counter .
diffPointer = &diff; - (correct answer)Assume that an int variable diff has already been
declared. Assume further a variable diffPointer of type "pointer to int " has also already
been declared. Write a statement that assigns the address of diff to diffPointer .
*strikeCounter * 4 - (correct answer)Assume that strikeCounter has already been
declared to be a "pointer to int ". Assume further that strikeCounter has been initialized -
- its value is the address of some int variable.
Write an expression whose value is four (4) times the value of the variable that
strikeCounter is pointing to.
, *strikeCounter = 27; - (correct answer)Assume that strikeCounter has already been
declared to be a "pointer to int ". Assume further that strikeCounter has been initialized -
- its value is the address of some int variable.
Write a statement that assigns the value 27 to the variable that strikeCounter is pointing
to.
*strikeCounter += 22; - (correct answer)Assume that strikeCounter has already been
declared to be a "pointer to int ". Assume further that strikeCounter has been initialized -
- its value is the address of some int variable.
Write a statement that adds 22 to the value of the variable that strikeCounter is pointing
to.
*ip3 = *ip1 + *ip2; - (correct answer)Assume that ip1 , ip2 , and ip3 have already been
declared to be of type "pointer to int ". Assume further that each of these pointer
variables have been initialized -- each points to some int variable.
Write a statement that computes the sum of the variables that ip1 and ip2 point to, and
assigns that value (the sum) to the variable that ip3 points to.
int *temp;
temp = xp;
xp = yp;
yp = temp; - (correct answer)The variables xp and yp have both been declared as
pointers to integers, and have been assigned values (i.e., they are each pointing to an
integer value). Write the code to exchange the values of these two variables (so that
after the swap xp points to what yp originally pointed to and vice-versa-- in other words,
in this exercise, you are swapping the pointers). Declare any necessary variables.
int x = 0;
ANSWERS
&diff - (correct answer)Assume the variable diff has already been declared. Write an
expression whose value is the address of diff .
int *ip; - (correct answer)Declare a variable ip that can be assigned the address of an int
variable. In other words, declare ip to be of type "pointer to int ".
char *cp; - (correct answer)Declare a variable cp that can be assigned the address of an
char variable. In other words, declare cp to be of type "pointer to char ".
double *dp; - (correct answer)Declare a variable dp that can be assigned the address of
a double variable. In other words, declare dp to be of type "pointer to double ".
counterPointer = &counter; - (correct answer)Assume that an int variable counter has
already been declared. Assume further a variable counterPointer of type "pointer to int "
has also already been declared. Write a statement that makes counterPointer "point" to
counter .
diffPointer = &diff; - (correct answer)Assume that an int variable diff has already been
declared. Assume further a variable diffPointer of type "pointer to int " has also already
been declared. Write a statement that assigns the address of diff to diffPointer .
*strikeCounter * 4 - (correct answer)Assume that strikeCounter has already been
declared to be a "pointer to int ". Assume further that strikeCounter has been initialized -
- its value is the address of some int variable.
Write an expression whose value is four (4) times the value of the variable that
strikeCounter is pointing to.
, *strikeCounter = 27; - (correct answer)Assume that strikeCounter has already been
declared to be a "pointer to int ". Assume further that strikeCounter has been initialized -
- its value is the address of some int variable.
Write a statement that assigns the value 27 to the variable that strikeCounter is pointing
to.
*strikeCounter += 22; - (correct answer)Assume that strikeCounter has already been
declared to be a "pointer to int ". Assume further that strikeCounter has been initialized -
- its value is the address of some int variable.
Write a statement that adds 22 to the value of the variable that strikeCounter is pointing
to.
*ip3 = *ip1 + *ip2; - (correct answer)Assume that ip1 , ip2 , and ip3 have already been
declared to be of type "pointer to int ". Assume further that each of these pointer
variables have been initialized -- each points to some int variable.
Write a statement that computes the sum of the variables that ip1 and ip2 point to, and
assigns that value (the sum) to the variable that ip3 points to.
int *temp;
temp = xp;
xp = yp;
yp = temp; - (correct answer)The variables xp and yp have both been declared as
pointers to integers, and have been assigned values (i.e., they are each pointing to an
integer value). Write the code to exchange the values of these two variables (so that
after the swap xp points to what yp originally pointed to and vice-versa-- in other words,
in this exercise, you are swapping the pointers). Declare any necessary variables.
int x = 0;