C++ Interview Q & A 7
C++ Interview Q & A 7
1. This set of questions came from a prominent gaming company. As you can
see, the answers are not given (the interviews are typically conducted by
senior developers), but there’s a set of notes with common mistakes to avoid.
1. Explain which of the following declarations will compile and
what will be constant - a pointer or the value pointed at:
const char *
char const *
char * const
Note: Typical wrong answer: Yes, the program will crash in an attempt
to delete a null pointer. The candidate does not understand pointers. A
very smart candidate will ask whether delete is overloaded for the
class T.
Note: Hint to the candidate about the base platform they’re developing
for. If the person still doesn’t find anything wrong with the code, they
are not experienced with C++.
27.What does the following code do and why would anyone write
something like that?
28. void send (int *to, int * from, int count)
29. {
30. int n = (count + 7) / 8;
31. switch ( count % 8)
32. {
33. case 0: do { *to++ = *from++;
34. case 7: *to++ = *from++;
35. case 6: *to++ = *from++;
36. case 5: *to++ = *from++;
37. case 4: *to++ = *from++;
38. case 3: *to++ = *from++;
39. case 2: *to++ = *from++;
40. case 1: *to++ = *from++;
41. } while ( --n > 0 );
42. }
43. }
44.In the H file you see the following declaration:
45. class Foo {
46. void Bar( void ) const ;
47. };