Elance C++ Test Answers 2015
·
What does OOD stand for?
Object-oriented database
Operating on Objects in Design
Object-Oriented Design
Overly Objective Design
If class B inherits class A, A::x() is
declared virtual and B::x() overrides A::x(), which method x() will be called
by the following code: B b; b.x();
A::x()
A::x() followed by B::x()
B::x()
B::x() followed by A::x()
What does the following create: int * p; p=0;?
Neither Null nor Void
Both Null and Void
Void pointer
Null pointer
std::make_heap() converts a range into a heap
and std::sort_heap() turns a heap into a sorted sequence.
true
false
Consider the following: namespace myNamespace
{ int a; int b; } How would the main part of the program access myNamespace
variable a?
a
myNamespace::a
myNamespace:a
In C++, a single line comment needs to be
begun with
a leading //.
all of these
a leading /**.
Choose the valid C++ function declaration
which passes the function parameters by reference.
ref myFunction(int a, int b, int c)
void myFunction( int a, int b, int c)
void myFunction (int& a, int& b, int&
c)
Which of the following operators below allow
you to define the member functions of a class outside the class?
?
,
::
:%
C++ statements are separated by this symbol:
Semi-colon (;)
Addition sign (+)
Colon (:)
Hash symbol (#)
Which of the following is a reserved word in
C++?
Char
CHAR
char
character
int, long, double and string can all be
described as:
Attributes
Data Types
Constructors
Class members
Which two variables are the same?
Test and test
test and test
TEST and test
Which of the following is a valid C++ function
declaration which does not return a value?
myFunction( int a, int b)
void myFunction( int a, int b)
int myFunction( int a, int b)
The C++ programming language derived from:
Fortran
C
French
Basic
How do you declare an integer variable x in
C++?
x is integer;
int x;
declare x as integer;
int<x>;
x int;
The statement i += 5; has the same meaning as:
i * 5++;
i == i;
5 += 1;
i = i + 5;
Which of the following is not a loop
structure?
stop when loop
do while loop
for loop
Which of the following is not a fundamental
data type in C++?
wide
bool
char
Which of the following is a valid variable
declaration statement?
int a; b; c;
int a:
int a, b, c;
Which of the following is not a C++ primitive
type?
real
double
int
float
A C++ program begins its execution at the
none of these
main function.
function specified by the preprocessor.
This symbol calls the pre-processor to include
the specified system files such as iostream.
Forward Slash (/)
Hash Symbol (#)
Ampersand (&)
Exclamation Mark (!)
If you have two different C++ functions which
have the same name but different parameter types, it is called...
function overloading.
inline functions.
recursive functions.
Choose the function declaration which you
would use if you did not need to return any value.
myfunction(void)
myfunction()
void myfunction()
The output of this program is int main () {
cout << "Hello World!"; return 0; }
Hello World
Hello World!
Syntax error
0
Which of the following statements tests to see
if the sum is equal to 10 and the total is less than 20, and if so, prints the
text string "incorrect."?
if( (sum == 10) || (total < 20)
)printf("incorrect.");
if( (sum == 10) && (total < 20)
)printf("incorrect.");
ctrl+alt+del
None of these options
Which statement assigns to variable a the
address of variable b?
a = &b;
a = b;
a = *b;
True or False: Classes can contain static
member variables which are global to the class and can be accessed by all
objects of the same class.
True
False
An ordered and indexed sequence of values is
an:
List of Parameters
Group
Array
Class
True or False: A void pointer is a special
type of pointer which indicates the absence of a type for the pointer.
False
True
Which is a valid comment statement in C++?
Both of these
/* this is a comment */
// this is a comment
What does the following statement mean? const
int a = 50;
The initial value of a is 50 but you can change it.
The value of a cannot change from 50.
none of these
What is the value of i after the following
statement(s)? int i (4.36);
4.36
4
4.4
5
char * array = "Hello"; char array[]
= "Hello"; What is the difference between the above two, if any, when
using sizeof operator ?
The sizeof of an array gives the number of elements
in the array but sizeof of a pointer gives the actual size of a pointer
variable.
The sizeof returns the size of the char type (1) in
both cases.
Choose the statement which declares a function
with a default value for an argument.
void myfunction(int a)
void myfunction(int a=2)
void myfunction(int a;a = 2)
What is the size in bytes of an int variable
on a 32-bit system?
1
2
4
3
What is an advantage to using C++ Templates?
all of these
templates are typesafe
increase code flexibility
reduce code duplication
What does the following statement do:
std::cout << x;?
Writes the contents of x to stdout.
Writes the character 'x' to stdout.
Stores the contents of x in the cout variable.
How would you declare a pointer which has no
type in C++?
null * data;
int * data;
void * data;
void data;
What is the value of a = 11 % 3;?
2
3
1
0
What does operator+ perform on two instances
of std::string?
Address addition
Nothing
none of these
String concatenation
The printmsg function does not require any
arguments. Choose the statement which calls the function.
printmsg();
void printmsg();
printmsg;
In the following line of C++ code, int
foo[50]; what does the number 50 represent?
The maximum integer value that can be placed in the
array.
The number of integer elements the array shall
hold.
The initial value of the first array element.
Choose the statement which declares a function
with arguments passed by reference.
void myfunction(int a, int b)
void myfunction(int* a, int* b)
void myfunction(int& a, int& b)
Can constructors be overloaded?
No
Depends on the situation.
Yes
A global variable is a variable declared in
the main body of the source code, outside all functions, while a local variable
is one declared...
within the body of a function or block.
all of these
outside the main body of the function.
The process of making one variable appear to
be another type of data is called TYPECASTING. The two processes are:
Expletive and Implicit
Single and double
Explicit and Implicit
Forecasting and Fivecasting
What does the sizeof(arg) operator do?
returns the maximum value of arg
returns the size in bytes of arg
returns the length in characters of arg
Classes can contain static member variables
which are global to the class and...
their values will change for each object of the
same class.
can be accessed by all objects of the same class.
none of these
Consider this code fragment: a = 25; b =
&a; What does b equal?
value contained in the address of a
25
address of a
Which is(are) an example(s) of valid C++
function prototype(s)?
int myFunction(int, int);
int myFunction( int a, int b);
all of these
If you have an external function which needs
access to private and protected members of a class, you would specify the
function as...
void myClass myFunction(myClass);
myClass myFunction(friend myClass);
friend myClass myFunction(myClass);
True or False: In C++, a comment can only be
specified with a leading //.
True
False
What is the difference between a class and a
struct
The members of a class are private by default, and
the members of a struct are public by default.
You cannot overload an operator in a struct.
You can declare functions in a class, you cannot
declare functions in a struct.
They are the same.
Which is a requirement when using overloaded
C++ functions?
Return types for the overloaded functions can be
different.
Argument lists for the overloaded functions must be
different.
One function can be static and the other can be
nonstatic.
The default access level assigned to members
of a class is...
private
protected
default
public
What will "int a = 'a';" do?
It will declare a new variable a and set it to its
previous value.
It will cause an infinite loop.
Nothing, it is an error and won't compile.
It will declare a new variable a and set it to 97
(assuming a machine that uses ASCII).
A structure item exists in your code with an
integer member units. You have the following variable declaration: item *
myItem;. How do you access the value of units?
*(myItem.units)
myItem.units
myItem->units
Why would you use the preprocessor directive
#include <iostream> in your C++ program?
Your program uses cout function calls.
Your program uses standard elements.
Your program uses a return value.
What is the difference between classes and
structures?
Elements of a class are private by default
Structures cannot include types
Classes can include members
None of these
Which of the following is a valid variable
identifier in C++?
class
1_str
m_test
What's the difference between an array and a
vector?
Vectors can hold data of different types, but
arrays can only hold data of one type
Arrays take more memory to store data than vectors
Vectors can be dynamically resized, but an array's
size is fixed
Vectors don't support random access to elements,
but arrays do
Arrays require the STL, but vectors are native to
C++
What is the right way to place an opening
curly bracket in C++?
Opening curly brackets should always be placed on
the next line after the statement referring to the block it defines.
Curly brackets are not legal in C++ code.
Opening curly brackets should always be placed on
the same line with the statement referring to the block it defines.
There is no C++ rule about placing curly brackets.
The dynamic memory requested by C++ programs
is allocated...
from extended memory.
from high memory.
from the memory heap.
from the memory stack.
Which of the following statements assigns the
hexadecimal value of 75 to a literal constant?
const int a = 0x4b;
int a = 0x4b;
const int a = 4b;
What does "int *p; p = 0;" do?
It sets p to nullptr.
It zeroes out the memory that p is pointing to.
Nothing, it's illegal and won't compile.
It crashes your program.
Given the following code sample: catch(…) {
cout << "exception";}. What do the ellipses indicate?
The handler will catch any type of error thrown.
all of these
none of these
The handler will only catch int exceptions.
What does the line: #include <iostream>
mean in a C++ program?
It tells the preprocessor to include the iostream
standard file.
It tells the preprocessor to include the iostream
standard file only if it it required by the program.
It tells the program to include the standard
library header files.
What is the value of 2--2?
4
0
2
Nothing, that is not a valid C++ expression.
-2
Which of the following can cause a memory
corruption error?
Freeing memory which has already been freed.
Using an address before memory is allocated and
set.
All of these
Which of the following is not a specific type
casting operator in the C++ language?
reinterpret_cast
const_cast
unknown_cast
dynamic_cast
Defined data types (typedef) allow you to
create...
alternate names for existing types in C++.
different types in C++.
Within a class declaration, the statement
"virtual int foo() = 0;" does what?
Declares a default virtual function.
Declares a pure virtual function.
Causes a compiler error.
Declares a volatile virtual function.
Where does the compiler first look for file.h
in the following directive: #include "file.h" ?
In the default directories where it is configured
to look for the standard header files
The same directory that includes the file
containing the directive.
In all directories specified by the PATH
environment variable on the machine.
What is the value of 7 == 5+2 ? 4 : 3?
4
7
3
Define a way other than using the keyword
inline to make a function inline
The function must be defined outside the class.
The function must be defined inside the class.
The function must be defined as the friend
function.
In C++, what is the difference between these two
declarations: void foo(); void foo(void);
One of them takes no value, the other takes any
value.
The first one is illegal.
The second one is illegal.
None, they are equivalent.
Can a struct have a constructor in C++?
No. Struct types do not support member functions.
No. Only class types allow constructors.
Yes.
What are the two valid boolean (bool) values
in C++?
true and false
TRUE and FALSE
True and False
Which of these is a difference between struct
and class types?
Structs only allow variable definitions. Classes
also allow function definition.
No difference.
Structs are public-inherited by default. Classes
are private-inherited by default.
There are no inheritances with structs. Classes may
be derived.
What is the size of the character array which
would hold the value "Helloo"?
8
7
6
In the following variable definition, if
declared inside a function body, what is the initial value of result: int
result; ?
undefined
0
NULL
What is the data type for the following:
L"Hello World"?
a wide character string
a string
an integer string
Which of the following rules apply to operator
overloading in C++?
Cannot redefine the meaning of built in types
Cannot have default arguments
Both of the other answers are correct.
True or False: A class that has a pure virtual
method can be instantiated.
False
True
std::vector<int> foo(5);
Initializes a vector with 5 elements of value 0.
Initializes a vector with an element with the value
5.
std::vector<int> foo {5}; (assume C++11)
Initializes a vector with 1 element of the value 5.
Initializes a vector with 5 elements with value 0.
Which is a valid variable initialization
statement?
int a = 0;
int a(0);
Both of these are valid
What of the following is not permitted in a
pure virtual class in C++?
private member variables
member variables
static member variables
All of these are permitted.
protected functions
Which class(es) can be used to perform both
input and output on files in C++?
All of the answers are correct.
ofstream
fstream
ifstream
A void pointer is a special type of pointer
which indicates the...
pointer has a NULL value.
absence of a type for the pointer.
none of these
class A { int x; protected: int y; public: int
z; }; class B: public A { }; What is the privacy level of B::y?
protected
private
public
B does not inherit access to y from A.
Which C++ keyword allows the compiler to
determine the type of a variable by the value used to initialized it?
abstract
var
auto
virtual
Which of the following calls method foo() from
the parent class Parent of the current class?
Parent.foo();
this->parent->foo();
Parent::foo();
Parent instance; instance.foo;
What is a virtual function in C++?
A class member function which does not need to be
defined in the base class.
A class member function that must be redefined in
derived classes.
A class member function that you expect to be
redefined in derived classes.
What does the "explicit" keyword do?
It makes the declaration of a default constructor
mandatory
It prevents a single-argument constructor from
being used in an implicit conversion
It requires a variable to reside in main memory
instead of a processor's cache
int *array = new int[10]; delete array;
This code will correctly free memory
This code has undefined behavior
In the code below: void foo(){ static int
x=10; } When is x created?
At the first call of foo().
When the process is created.
Every time foo() is called.
The code will not compile.
Suppose int * a = new int[3]; How would you
deallocate the memory block pointed by a?
delete a;
delete a[];
delete a[3];
delete[] a;
delete[3] a;
Which of the following statements uses a
Lambda expression?
bool is_odd = [](int n) {return n%2==1;};
int (*minus)(int, int) = subtract;
std::regex e ("\\b(sub)([^ ]*)");
Given the following, how many bytes of memory
does var occupy?: class a { int x; short y; }; a var[20];
Depends
4
This is invalid C++ code
120
160
What is the data range for an unsigned integer
value in C++ on a system where ints are 32 bits?
0 to 2,147,483,647
0 to 4,294,967,295
0 to 65,535
0 to 255
Which operator cannot be overloaded by a class
member function?
?
*
==
[]
++
Given: union a { int x; short y; }; a var[20];
How many bytes of memory does var occupy?
This is invalid C++ code
4
80
Depends
120
What is the time complexity of delete the
first variable in a deque object (e.g., deque<int> a;)?
O(1)
O(n)
O(logn)
O(n/2)
What is the guaranteed complexity of
std::push_heap?
O(n^2)
O(1)
O(log(n))
O(n)
String literals can extend to more than a
single line of code by putting which character at the end of each unfinished
line?
a newline (\n)
a backslash (\)
a tab (\t)
What number will the following function
return? int func() { int x = 0; { x++; int x = 2; x++; } x++; return x; }
code will not compile because "x" is declared
twice
4
2
1
3
What is the value of x after the following
code: int x = 0; if (x = 1) { x = 2; } else { x = 1; }
1
The code will not compile
2
0
Is the following legal C++ code? | char *str =
"abc" + "def";
No.
Yes, but only if you #include <string> first.
Yes.
No, you need to add "const" before
"char".
What is the proper way to use the .substr()
function on the following string to get the word "World"? string
aString = "Hello World!";
aString.substr(6,5);
aString.substr(5,5);
aString.substr(6,10);
aString.substr(5,10);
An anonymous namespace is used to...
support closures
nest namespaces
prevent external access to declarations local to a
compilation unit
disambiguate declarations from other namespaces
Which of the following is a potential side-effect
of inlining functions?
The size of the compiled binary increases
The size of program's stack segment increases
C++ standard guarantees that inlining does not
result in any adverse side-effects
The size of program's heap segment increases
class A { int x; protected: int y; public: int
z; }; class B: private A { }; What is the privacy level of B::z?
protected
public
private
B does not inherit access to z from A.
What type of exceptions can the following
function throw: int myfunction (int a);?
All
Standard
None
If you do not supply any constructors for your
class, which constructor(s) will be created by the compiler?
Both of these
Copy Constructor
Default constructor
How would you access "BLUE" in the
"Color" enum class? enum class Color { RED, BLUE, GREEN };
Color blue = Color.BLUE;
int blue = BLUE;
Color blue = Color::BLUE;
int blue = Color[1];
Will the code below compile without error?
struct c0 { int i; c0(int x) { i = x; } }; int main() { c0 x1(1); c0 x2(x1);
return 0; }
No. struct types do not have constructors.
No. c0 x2 ( x1 ) will return error.
Yes.
No. The constructor is not public.
What is the value of 10.10 % 3?
1.01
None, that is an invalid mix of types.
3.03
1
1.0
Where T is a type: std::vector<T>::at vs
std::vector<T>::operator[]:
at is equivalent to operator[]
at is always bounds checked. operator[] is not.
at is not always bounds checked. operator[] is.
Assuming you are using a 32-bit compiler on an
x86 platform, what would the result of sizeof(A) typically be? struct A { char
B; int* C; short D; };
16
4
Unknown; it is compiler and/or platform dependent
12
8
int a[] {1, 2, 3}; a[[] { return 2; }()] += 2;
What is the value of a[2]?
5
Undefined behavior
Compile error: malformed attribute.
3
4
What is the below code? struct code { unsigned
int x: 4; unsigned int y: 4; };
A struct declaration with 2 arrays of int.
A bit selector declaration.
A bit field structure declaration.
Invalid C++ code.
A struct with in place initialization of its
members.
Which is NOT a valid hash table provided by
the STL?
hash_multimap
hash_map
hash_multiset
hash_set
hash_table
What is the difference between: int a(0); and
int a = 0; ?
int a(0); is not legal code in C++ because int is
not a class
int a(0) calls the int ctor and int a=0 calls the
operator= of the int class
int a(0) works in C but int a = 0 works both in C
and C++
None
int a(0) happens at compile time and int a=0
happens at runtime
According to the C++ standard, what is
sizeof(void)?
It depends on the host computer's word size.
0
Nothing, void doesn't have a size.
1
4
What is the output of the following program?
#include <vector> #include <iostream> int main () {
std::vector<int> int_values {3}; for (auto const& vv: int_values) {
std::cout << vv; } }
Program fails during compilation
000
333
None of these
3
class A { int x; protected: int y; public: int
z; }; class B: public virtual A { }; What is the privacy level of B::x?
B does not inherit access to x from A.
private
public
protected
class foo { foo(){}; }; class boo : public foo
{ boo() : foo() {}; }; which standard allows compilation of this code.
none, the code wont compile
c++03
c++0x
c++98
c++11
Suppose that a global variable "x"
of type std::atomic<int> with an initializer parameter of 20 should be
added to a header and (if necessary) source file so it is available to all
files that include it. How should this be implemented where it will cause
neither compile nor linker errors when compiling multiple object files
together? Assume that a header guard and #include <atomic> is already
present in the header (though not shown in the answers), and that C++11 is
enabled.
In header: extern std::atomic<int> x; In
source: std::atomic<int> x = 20;
In header: extern std::atomic<int> x(20);
In header: extern std::atomic<int> x; In
source: std::atomic<int> x(20);
In header: std::atomic<int> x = 20;
In header: extern std::atomic<int> x; In
source: extern std::atomic<int> x(20);
Which of the following is not a member of
std::weak_ptr<T>?
weak_ptr(T *r) noexcept;
template<class Y> weak_ptr(weak_ptr<Y>
const& r) noexcept;
template<class Y>
weak_ptr(shared_ptr<Y> const& r) noexcept;
constexpr weak_ptr() noexcept;
Which function always returns an rvalue
reference from "x", which can be used to indicate the object is going
to be destroyed soon?
std::destroy(x)
std::xvalue(x)
std::shift(x)
std::move(x)
What is the type being defined here: typedef A
(B::*C)(D, E) const;
B is defined to be a class containing a constant
member function called A, taking arguments of types D and E, returning a
pointer to type C.
A is defined to be a constant function in namespace
B taking arguments of types D and E, returning a pointer to type C.
C is defined to be a constant member function
pointer of class B taking arguments of types D and E, returning type A.
What will be the output? auto fn = [](unsigned
char a){ cout << std::hex << (int)a << endl; }; fn(-1);
ff
0
Undefined
256
-1
How do you declare a pointer where the memory
location being pointed to cannot be altered, but the value being pointed to
can?
int const *x = &y;
const int *x = &y;
const int * const x = &y;
const int const *x = &y;
int * const x = &y;
What is the purpose of std::set_union?
Sets a value to the value of a union.
Constructs a sorted union of the elements from two
ranges.
Constructs an unsorted union of the elements from
two ranges.
Assigns one union to another union.
Assigns a value to a union.
The value of "(sizeof(short) ==
sizeof(int) && sizeof(int) == sizeof(long))" is
implementation defined
false
compiler error
true
int C++; What is the value of C now?
Whatever C was before plus one
C is still a good programming language but C++ is
better
1
This is invalid code in C++
undefined
What will be the output of the following C++
code ? #include<iostream> class A { int a; public: void foo()
{std::cout<<"foo";} }; int main() { A* trial=nullptr;
trial->foo(); }
foo
It's an incorrect program and causes segmentation
fault.
It's an incorrect program and can't be compiled
either.
Is it possible to create class instance placed
at a particular location in memory?
Yes, placement new does this.
Only by dirty hack with reinterpret_cast.
No. Only allocation on stack or in dynamic memory
is allowed.
Which of the following operators can you not
overload?
, (comma)
->
. (dot)
[]
()
std::deque<int> queue;
queue.push_back(1); int& ref = queue.back(); queue.push_back(2); Where does
ref point to?
Front of the queue
itr was invalidated by push_back
Back of the queue
const std::string * s; std::string const * g;
What can be said about s and g?
s is a modifiable pointer to an immutable string g
is an immutable pointer to a modifiable string
s is an immutable pointer to a modifiable string g
is a modifiable pointer to an immutable string
s is a modifiable pointer to an immutable string g
is an immutable pointer to an immutable string
both s and g are modifiable pointers to an
immutable string
class A { int x; protected: int y; public: int
z; }; class B: private A { public: using A::y; }; What is the privacy level of
B::y?
protected
public
B does not inherit access to y.
private
What would the following program print? class
Printer{ public: Printer(std::string name) {std::cout << name;} }; class
Container{ public: Container() : b("b"), a("a") {} Printer
a; Printer b; }; int main(){ Container c; return 0; }
Either "ab" or "ba".
Implementation dependent.
Always "ba"
Always "ab"
What is the value of "v"? auto
&p = 10; double v = p;
10
undefined
10.0lf
compilation error
signed int a = 5; unsigned char b = -5;
unsigned int c = a > b; What is the value of c?
0
true
1
255
With: struct foo { int a:3, b:4, :0; int c:4,
d:5; int e:3; }; Determine if each statement is true or false: Concurrent
modification of foo::a and foo::c is or might be a data race. Concurrent
modification of foo::a and foo::b is or might be a data race. Concurrent
modification of foo::c and foo::e is or might be a data race.
false false false
false true true
true false true
false true false
false false false
true true true
According to the IEEE standard, which of the
following will always evaluate to true if the value of "var" is NaN?
var == "NaN"
var < 0
var > MAX_DOUBLE
var != var
var == nan
Below code fails to compile. class A { public:
int GetValue() const { vv = 1; return vv; } private: int vv; }; Which of the
following choices results in fixing this compilation error?
Any one of the specified choices fixes compilation
error
Change the declaration of member 'vv' to 'mutable
int vv'
Change the declaration of member function
'GetValue' so it is 'non const'
If sizeof(int)==4 what is sizeof(long)?
At most 4
8
At least 4
You cannot know because it depends on the machine
4
Is the following well-formatted C++ code?
%:include <vector> int main (void) <% std::vector<int> ivec
<% 1, 2, 3 }; ??>
No, this is not valid C++ syntax.
Yes, it will compile.
Virtual inheritance is needed...
to inherit from classes in different modules
to enable runtime type information (RTTI)
to not get multiple ambiguous copies of members of
ancestor classes
to enable polymorphism
In the following class definition: class
my_lock { std::atomic<int> data; public: my_lock() : data{1} {} void
unlock() { data = 1; } void lock(); } which could be used to complete the lock
function, assuming the purpose of the above code is to create a mutex-like locking
mechanism? Assume C++11.
void my_lock::lock() { int exp(1); while
(!data.compare_and_swap(exp, 0)) exp = 1; }
void my_lock::lock() { int exp(0); while
(!data.compare_exchange_strong(exp, 1)) exp = 0; }
void my_lock::lock() { int exp(0); while
(!data.compare_and_swap(exp, 1)) exp = 0; }
void my_lock::lock() { exp = 0; }
void my_lock::lock() { int exp(1); while
(!data.compare_exchange_strong(exp, 0)) exp = 1; }
According to the C++11 standard, which of
these is a keyword?
size_t
char32_t
mint32_t
final
uint32_t
If after: a* var = new a(); var's value is
0x000C45710 What is its value after: delete var;
0xdeadbeef
0x000C45710
0xcccccccc
Undefined
0x00000000
int* a = {1, 2, 3}; | Where are the 1,2,3
values stored?
On the stack
On the heap
This code is not valid C++
If we have a class myClass , what can we say
about the code: myClass::~myClass(){ delete this; this = NULL; }
It won't compile
It is incorrect, it does not release any of the
member variables.
It is correct, we avoid memory leaks.
It will cause a stack overflow
What does "int *p = malloc(2);" do?
It will make p point to an uninitialized two-byte
piece of memory allocated from the heap.
It will make p point to the number 2.
Nothing, it will yield a type mismatch compiler
error.
It will crash your program (an int is four bytes
long, not two).
What is the value of bar(1) in: int foo(int
&x) { return ++x; } int bar(int x) { x += foo(x); return x; }
4
1
3
2
None, that is not valid C++ code.
What can we say about: myClass::foo(){ delete
this; } .. void func(){ myClass *a = new myClass(); a->foo(); }
It won't compile
It will raise a segmentation fault
It will raise a stack overflow
None of these.
What does operator -> () do?
Defines the structure dereference operator for a
class
This operator does not exist in C++
Defines the structure reference operator for a
class
Creates a virtual this pointer that can be used
outside the scope of the class
Lets you define the pointer returned by this for a
class
double a = 1.0; double *p = &a; a = a/*p;
Which of the following statements about the code is true?
None of the above.
Variable a is divided by the address of itself.
/* means the start of comments.
Variable a is divided by the value of itself.
What will a declaration such as “extern
"C" char foo(int);” do?
It tells the linker that it should find foo in the
external section named "C" in the compiled file.
It ensures that foo's mangled link name matches
that of the C compiler so it can be called from C functions.
Nothing, it is a syntax error.
It says that foo is an external function that will
be compiled by the C compiler.
It tells the compiler that it should use C's
calling convention for storing parameters and return values on the stack.
What will this program print? #include
<iostream> void f(int){std::cout << "f ";} int
g(){std::cout << "g "; return 0;} int h(){std::cout <<
"h "; return 1;} int main(){ f((g(), h())); return 0; }
Always "h g f "
Always "g h f "
Implementation dependent: "g h f " or
"h g f "
Compilation error: f() takes only one argument
Can a static member function be declared as
const?
No
Yes
Depends
What type of exceptions will the following
function throw: int myfunction (int a) throw();?
None
Int
All
What is the effect of "const"
following a member function's parameter declarations?
The function may be called on a const qualified
object, and treats the object as const qualified.
The function cannot change the values of its
parameters.
The function returns the same value for each set of
arguments.
The function can only be called on a const
qualified instance of the class.
In C++ the three STL (Standard Template
Library) container adapters are:
stack, queue, priority_queue
stack, linked_list, priority_queue
vector, queue, list
stack, linked_list, queue
What is the value of (false - ~0)?
Unknown. That's implementation dependent.
Nothing. It's a type mismatch error.
1
-1
0
Identifying classes by their standard
typedefs, which of the following is NOT declared by the standard C++ library?
ostream & ends( ostream & )
istream & istream::operator >> ( void *
& )
ostream & ostream::operator << (
streambuf * )
istream & istream::operator >> (
streambuf & )
ostream & ostream::operator << ( void * )
Subscribe to:
Posts (Atom)