False. C++ uses zero-origin indexing, which means the seventh element of the array has index six; the eight array element has index seven.
and was baffled when it wouldn't compile. What did your colleague do wrong?char * in, out; in = "hello"; out = "good bye";
Your colleague forget that each variable has to be declared a pointer:
char * in, * out;
When the constructor is called, the class instance is uninitialized; it is the constructor's responsibility initialize the instance. The constructor should only call member functions it knows will access parts of the instance that have been initialized when the method is called.
Declaring an class instanceconst widget w;
const
means the instance can't be changed (or
at least observably changed).
Friend functions violate encapsulation because they exist outside the class with which they are friends but yet have access to all the internal state of class instances.
so that the fully-parenthesized expression has the same evaluation order as the given expression. An expression is fully parenthesized when each binary operator operator has its own set of parentheses.a - 5 + 6 >= a + 3 * 2
(((a - 5) + 6) >= (a + (3 * 2)))
++(x + 1)
is invalid; explain why.
The prefix ++
operator adds one to the value of a variable and stores the
new value back in the variable. The expression x + 1
isn't a variable;
it's a numeric value and can't store anything.
do
S
while(
B)
using a while statement.
bool b = true; while (b) { S; b = B; }
unsigned vowell_count(const char * str) { unsigned c = 0; while (*str) if (is_vowell(*str++)) c++; return c; }
which of the two parameters might be declared as a reference inf(a, 10);
f
's
declaration. Explain your answer.
The first parameter might be a reference parameter; the second parameter cannot be, because it's a number and not a variable.
int find(int a[], int x);
find()
should return the index of the element in a
that equals x
or -1
if no element in a
equals x
. Can you write this function?
Explain your answer.
You cannot, because you don't know how big a
is.
>>
stream extraction operator?
You would need to write a differently named stream extraction operator for each value type you wanted to read. Because you can't create new operators, you'd have to write the stream extractions as functions, for example
widget get_widget(std::istream &) { /* whatever */ }
This page last modified on 16 January 2007.