In the workplace, most of you will work on large projects as a member of a team. Each team member will have an assigned piece of the overall project. In the end, all of the pieces must fit together like the pieces of a jigsaw puzzle. Everyone will work from a common set of requirements, ensuring the pieces fit together. If one team member goes "cowboy" and makes changes contrary to the requirements, the pieces won't fit together. When this happens, the other team members will meet the cowboy in the parking lot and "throw him or her a party."
The questions on the worksheets are like tiny little requirements. You are not at liberty to make changes like changing the name of a variable or a structure. Please read the questions carefully. Also, remember that C++ is case sensitive: bar is not the same as Bar.
It's very rare for anyone to learn everything about a concept with just one learning experience. You must be willing to return to previously presented concepts and review them as needed. For example, the following answers are more compact and meaningful if you know what is meant by:
data_type variable_name;
int counter;
char* cptr;
variable = expression;
counter = 0;
int counter = 0;
testvar
.
&testvarCompare this question to Q3 and Q14.
char_pointer
whose data type is a pointer to a char.
char* char_pointerCompare this question to Q4 and Q15.
double_pointer
whose type is a pointer to a double.
double* double_pointerCompare this question to Q4 and Q15.
testptr
points to a variable testvar
, write an expression that represents the contents of testvar
but that does not use its name.
*testptrCompare this question to Q5 and Q16.
The size of a pointer is fixed and is not affected by initializing or not initializing the contents of the pointer.
bar
is the name of a class. Write a statement that defines a variable named bar_ptr
that can point to a bar
object. What it means to define a variable was introduced in section 1.6 of the text.
bar* bar_ptr;
bar* bar_ptr; bar_ptr = new bar; |
bar* bar_ptr; bar_ptr = new bar(); |
bar* bar_ptr = new bar; |
bar* bar_ptr = new bar(); |
Until very recently, parentheses were not only not needed when calling a default constructor, but using them was an error. The most recent version of C++ allows both versions listed here as correct. Defining and initializing a variable are two distinct operations that can be implemented with two statements or combined into a single statement.