UpWork (oDesk) & Elance C++ Programming Test Question & Answers are really very important to pass UpWork & Elance test. You will get top score at this skill test exam. If you found any problem or wrong answer please inform me via contact or comments. We will try to solve it in short. This test is very valueable to acquire knowledge of this skill. Lets Start test.
Ques : Consider the following code:
class A {
typedef int I; // private member
I f();
friend I g(I);
static I x;
};
Which of the following are valid:
Ans :
A::I A::f() { return 0; }
A::I g(A::I p = A::x);
A::I g(A::I p) { return 0; }
Ques : Consider the following class hierarchy:
class Base
{
}
class Derived : public Base
{
}
Which of the following are true?
Ans : Derived can access public and protected member functions of Base + The following line of code is valid: Base *object = new Derived();
Ques : What linkage specifier do you use in order to cause your C++ functions to have C linkage
Ans : extern "C"
Ques : Sample Code
typedef char *monthTable[3];
Referring to the code above, which of the following choices creates two monthTable arrays and initializes one of the two?
Ans : monthTable winter,spring={"March","April","May"};
Ques : What access specifier allows only the class or a derived class to access a data membe
Ans : protected
Ques : What is the output of the following code segment?
int n = 9;
int *p;
p=&n;
n++;
cout << *p+2 << "," << n;
Ans : 12,10
Ques : What does ADT stand for?
Ans : Abstract data type
Ques : Consider the sample code given below and answer the question that follows.
class Shape
{
public:
virtual void draw() = 0;
};
class Rectangle: public Shape
{
public:
void draw()
{
// Code to draw rectangle
}
//Some more member functions.....
};
class Circle : public Shape
{
public:
void draw()
{
// Code to draw circle
}
//Some more member functions.....
};
int main()
{
Shape objShape;
objShape.draw();
}
What happens if the above program is compiled and executed?
Ans : A compile time error will be generated because you cannot declare Shape objects
Ques : Consider the sample code given below and answer the question that follows.
class Person
{
public:
Person();
virtual ~Person();
};
class Student : public Person
{
public:
Student();
~Student();
};
main()
{
Person *p = new Student();
delete p;
}
Why is the keyword "virtual" added before the Person destructor?
Ans : To ensure that the destructors are called in proper orde
Ques : If input and output operations have to be performed on a file, an object of the _______ class should be created.
Ans : fstream
Ques : In the given sample Code, is the constructor definition valid?
class someclass
{
int var1, var2;
public:
someclass(int num1, int num2) : var1(num1), var2(num2)
{
}
};
Ans : Yes, it is valid
Ques : Consider the sample code given below and answer the question that follows.
template Run(T process);
Which one of the following is an example of the sample code given above?
Ans : A template function declaration
Ques : Which of the following sets of functions do not qualify as overloaded functions?
Ans : void x(int,char) int *x(int,char)
Ques : Consider the sample code given below and answer the question that follows.
1 class Car
2 {
3 private:
4 int Wheels;
5
6 public:
7 Car(int wheels = 0)
8 : Wheels(wheels)
9 {
10 }
11
12 int GetWheels()
13 {
14 return Wheels;
15 }
16 };
17 main()
18 {
19 Car c(4);
20 cout << "No of wheels:" << c.GetWheels();
21 }
Which of the following lines from the sample code above are examples of data member definition?
Ans : 4
Ques : Which of the following statements about function overloading, is true?
Ans : Function overloading is possible in both C and C++
Ques : You want the data member of a class to be accessed only by itself and by the class derived from it. Which access specifier will you give to the data member?
Ans : Protected
Ques : Consider the sample code given below and answer the question that follows.
class Person
{
string name;
int age;
Person *spouse;
public:
Person(string sName);
Person(string sName, int nAge);
Person(const Person& p);
Copy(Person *p);
Copy(const Person &p);
SetSpouse(Person *s);
};
Which one of the following are declarations for a copy constructor?
Ans : Person(const Person &p);
Ques : Which of the following member functions can be used to add an element in an std::vector?
Ans : push_back
Ques : Which of the following are NOT valid C++ casts
Ans : void_cast
Ques : Consider the sample code given below and answer the question that follows:
char **foo;
/* Missing code goes here */
for(int i = 0; i < 200; i++)
{
foo[i] = new char[100];
}
Referring to the sample code above, what is the missing line of code?
Ans : font size=2>foo = new char*[200];
Ques : Consider the line of code given below and answer the question that follows.
class screen;
Which of the following statements are true about the class declaration above?
Ans : The syntax is correct
Ques : Which of the following are true about class member functions and constructors?
Ans : A member function can return values but a constructor cannot
Ques : Consider the following code:
#include
int main(int argc, char* argv[])
{
enum Colors
{
red,
blue,
white = 5,
yellow,
green,
pink
};
Colors color = green;
printf("%d", color);
return 0;
}
What will be the output when the above code is compiled and executed?
Ans : 11
Ques : Which of the following statements regarding functions are false?
Ans : You can create arrays of functions
Ques : Consider the following code:
#include
using namespace std;
class A
{
public :
A()
{
cout << "Constructor of A\n";
};
~A()
{
cout << "Destructor of A\n";
};
};
class B : public A
{
public :
B()
{
cout << "Constructor of B\n";
};
~B()
{
cout << "Destructor of B\n";
};
};
int main()
{
B *pB;
pB = new B();
delete pB;
return 0;
}
What will be the printed output?
Ans : Constructor of A Constructor of B Destructor of B Destructor of A
Ques : Consider the following code:
template void Kill(T *& objPtr)
{
delete objPtr;
objPtr = NULL;
}
class MyClass
{
};
void Test()
{
MyClass *ptr = new MyClass();
Kill(ptr);
Kill(ptr);
}
Invoking Test() will cause which of the following?
Ans : Code will execute properly
Ques : Consider the following statements relating to static member functions and choose the appropriate options:
1. They have external linkage
2. They do not have 'this' pointers
3. They can be declared as virtual
4. They can have the same name as a non-static function that has the same argument types
Ans : Only 1 and 2 are true
Ques : What will be the output of the following code?
class b
{
int i;
public:
virtual void vfoo()
{
cout <<"Base ";
}
};
class d1 : public b
{
int j;
public:
void vfoo()
{
j++;
cout <<"Derived";
}
};
class d2 : public d1
{
int k;
};
void main()
{
b *p, ob;
d2 ob2;
p = &ob;
p->vfoo();
p = &ob2;
p->vfoo();
}
Ans : Base Derived
Ques : Consider the following code:
#include
using namespace std;
int main()
{
cout << "The value of __LINE__ is " <<__line__ span="">
return 0;
}
What will be the result when the above code is compiled and executed?
Ans : The code will compile and run without errors
Ques : Which of the following STL classes is deprecated (i.e. should no longer be used)?
Ans : ostrstream
Thanks for watching this test Question & Answers. Please don't forget to leave a comment about this post. You can also find some more effective test question & answers, information, techtunes, technology news, tutorials, online earning information, recent news, results, job news, job exam results, admission details & another related services on the following sites below. Happy Working!
News For Todays ARSBD UpWorkElanceTests ARSBD-JOBS DesignerTab UpLance
We recommend you to subscribe us to get update from your email. EmoticonEmoticon