1. Some words, when followed by a colon, have special meanings to yahoo. What is perfermed by the link:Operator?
a. it shows all the outbound links from the url
b. It shows how many pages of the site yahoo is pointing to
c. It shows all the pages that point to that url
d. It show url's with broken links
2. Which blackhat Seo techniques is characterized by a method to decieve search engine, by detecting the search engine bot and "feeding" it with a different HTML code than the HTML actually served to users?
a.Coaling
b.Foisting
c.Slighting
d.Cloaking
3. Why is it bad idea from SEO perspective to host free articles and write ups that are very common on the internet?
a.Because they will not lead to fresh traffic
b.Because you could be penalize by search engine for using duplicate contents
c.Because you will not get the benefits of proper keyword targeting
d.because people could turn up claiming copyright infirigement
4. What will happen if you type the word 'Certification-Networking' in the google search box?
a.Google will find the web pages about "certification" and also containing the word "networking"
b.Google will find ALL the web pages containing the word word "Certification" and "Networking"
c.*Google will find ALL the web pages in which the words "Certification" and "Networking" appear together.
d.Google will find the web pages about Certification that do not contain the word Networking
5. Which of the following factors does google take into account while accessing whether or not a website is an authority website?
a. The frequency with which the contents of the website is updated
b. the number of web pages containing relevant information on the main theme of the website
c.*The number of in-bound natural links related to the website's theme (or keywords)
d. None of the above
6. What is keyword density?
a.The number of times the keyword is used / (divided by) the total word count on page - (minus) the total words in HTML on the page
b.The number of times the keyword is used x (multiply by) the total word count on page.
c.The number of times the keyword is used in the page description
d.The number of times the keyword is used in the page title
e*The number of times the keyword is used / (divided by) the total word count on the page.
7. Which of the following statement about FFA pages are true?
a.They are greatly beneficial to SEO
b.They are also called Link Farms
c.They are Paid Listings
d*They contain numerous inbound links
8. What is the illegal act of copying of a page by unauthorized parties in order to filter off traffic to another site called?
a.Traffic jacking
b.Visitors Jacking
c.View Jacking
d* Page Jacking
9. What is the most likely time period required for getting a google page ranking?
a.1 week
b. 3 weeks
c. 1 month
d.* More than 3 months
10. Which of the following can be termed as a good keyword selection and placement strategies?
a* Targeting synonyms of the main keyword, A & D
b.Targeting the highest searched keywords only
c.Copying competitor keywords
d.Optimizing 5 or more keywords per page (check)
11. Some words, when followed by a colon, have special meanings to yahoo. What is perfermed by the link:Operator?
a. it shows all the outbound links from the url
b. It shows how many pages of the site yahoo is pointing to
c. It shows all the pages that point to that url
d. It show url's with broken links
12. Which blackhat Seo techniques is characterized by a method to decieve search engine, by detecting the search engine bot and "feeding" it with a different HTML code than the HTML actually served to users?
a.Coaling
b.Foisting
c.Slighting
d.Cloaking
13. Why is it bad idea from SEO perspective to host free articles and write ups that are very common on the internet?
a.Because they will not lead to fresh traffic
b.Because you could be penalize by search engine for using duplicate contents
c.Because you will not get the benefits of proper keyword targeting
d.because people could turn up claiming copyright infirigement
14. What will happen if you type the word 'Certification-Networking' in the google search box?
a.Google will find the web pages about "certification" and also containing the word "networking"
b.Google will find ALL the web pages containing the word word "Certification" and "Networking"
c.*Google will find ALL the web pages in which the words "Certification" and "Networking" appear together.
d.Google will find the web pages about Certification that do not contain the word Networking
15. Which of the following factors does google take into account while accessing whether or not a website is an authority website?
a. The frequency with which the contents of the website is updated
b. the number of web pages containing relevant information on the main theme of the website
c.*The number of in-bound natural links related to the website's theme (or keywords)
d. None of the above
16. What is keyword density?
a.The number of times the keyword is used / (divided by) the total word count on page - (minus) the total words in HTML on the page
b.The number of times the keyword is used x (multiply by) the total word count on page.
c.The number of times the keyword is used in the page description
d.The number of times the keyword is used in the page title
e*The number of times the keyword is used / (divided by) the total word count on the page.
17. Which of the following statement about FFA pages are true?
a.They are greatly beneficial to SEO
b.They are also called Link Farms
c.They are Paid Listings
d*They contain numerous inbound links
18. What is the illegal act of copying of a page by unauthorized parties in order to filter off traffic to another site called?
a.Traffic jacking
b.Visitors Jacking
c.View Jacking
d* Page Jacking
19. What is the most likely time period required for getting a google page ranking?
a.1 week
b. 3 weeks
c. 1 month
d.* More than 3 months
20. Which of the following can be termed as a good keyword selection and placement strategies?
a* Targeting synonyms of the main keyword (ans) A & D
b.Targeting the highest searched keywords only
c.Copying competitor keywords
d.Optimizing 5 or more keywords per page (check)
21. Google displays up to ------------------------ characters of a web pages title tag
a.*56
b.60 * B & C
c.66
d.80
22. Which of the following fact about Alexa are correct
a.*Alexa provides free data on relative website visitors traffic
b. Alexa and Quancast provide information on visitors household income
c.Alexa is baised towards US based traffic
d.Quantcast only track people who have installed the quantcast toolbar
23. What is the name of the search engine technology due to which a query for the word "actor" will aslo show search result for related word such as actress, acting or act?
a.Spreading
b.Dilating
c.RSD (real time synonyms detection)
d.Stemming
e.Branching
24.Do search engine such as google detect unnatural linking patterns by checking the class C IP address of the page where the link to the website originates
a* Yes
b No
25. Which of the following conditions will google treat favorably from the "Relevancy" perspective.
a.The website offering product and services to the visitors country
b.*A website that provides Free content for related keywords
c.Hidden keywords on the homepage matching search term
d.Image alt tag on the homepage matching search term
26. Which of the following website design guideline has been recommended by google?
a.Having a clear hierachy and text links
b.*Every page should be reachable from atleast one static text link
c.If the sitemap is larger than 100 or so links, you should break the sitemap into separate pages
d.Keep the links on a given page to a reasonable number (fewer than 100)
e. Use less than 30 images or graphics per page
27. What is the main reason for the effectiveness of Optimizing a web page towards a long tails keyword search? Recheck
a.There are more long tail searches than shorter keyword queries
b.*Search engine often pass on long tail searches to lesser or new website
c.Search engine do not pass on long tail search traffic to website that rank high for shorter keyword searches (check)
d. There are fewer webvsite that have targeted such keyword's
28 Which of the following statement is correct with regard's to the images within a web page?
a.Images can not be spidered by the search engine (check)
b. Important keywords related to the image should be plcaed in the ALT text
c.Images should always be kept close to the top of a web page
d. Image maps should be used while including the images
29. What does the 302 server Response Code signify?
a.* It signifies conflict, too many people wanting the same file at the same time
b.The page has been permanently removed
c.The method you are using to access the file is not allowed
d.The page has temporarily moved
e.What you requested is just too big to process
30. State whether the following statement is true or false. A sitemap provide a list of natural links to user accessible pages on a website
a.*True
b.Fals
Sunday, September 18, 2011
Saturday, September 17, 2011
oDesk C++ Test Answer
1)Consider the following code:
#include
using namespace std;
int main()
{
cout << "The value of __LINE__ is " <<__LINE__;
return 0;
}
What will be the result when the above code is compiled and executed?
Ans: c. The code will compile and run without errors
2) Base class members are made accessible to a derived class and inaccessible to rest of the program by _____.
Ans: protected access specifier
3) Which of the following is not a standard STL header?
Ans: a.
4) Which of the following are true about class and struct in C++:
Ans: In a class all members are private by default, whereas in struct all members are public by default
5)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
6)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. A::I A::f() { return 0; }
b. A::I g(A::I p = A::x);
c. A::I g(A::I p) { return 0; }
d. A::I A::x = 0;
7)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: a. Yes, it is valid
8)Which of the following STL classes is deprecated (ie should no longer be used)
ostrstream
ostringstream
ostream
wostream
Ans: ostrstream
9)Which of the following statements are true about C++ vector class?
a. vector::empty deletes all elements of the vector
b. vector::erase can be used to delete a single element and a range of elements of the vector
c. After calling, vector::erase causes some of the iterators referencing the vector to become invalid
d. vector::count returns the number of elements in the vector
e. vector::size returns the number of elements in the vector
f. vector::capacity returns the number of elements in the vector
Ans: b. vector::erase can be used to delete a single element and a range of elements of the vector
c. After calling, vector::erase causes some of the iterators referencing the vector to become invalid
e. vector::size returns the number of elements in the vector
10)Consider the following code:
class BaseException
{
public:
virtual void Output()
{
cout << "Base Exception" << endl;
}
};
class DerivedException : public BaseException
{
public:
virtual void Output()
{
cout << "Derived Exception" << endl;
}
};
void ExceptionTest()
{
try
{
throw new DerivedException();
}
catch (DerivedException ex)
{
ex.Output();
}
catch (...)
{
cout << "Unknown Exception Thrown!" << endl;
}
}
Invoking Exception Test will result in which output?
Ans: c. Unknown Exception Thrown
11)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: b. Base Derived
12)What will be the output of the following code?
class A
{
public:
A():pData(0){}
~A(){}
int operator ++()
{
pData++;
cout << "In first ";
return pData;
}
int operator ++(int)
{
pData++;
cout << "In second ";
return pData;
}
private:
int pData;
};
void main()
{
A a;
cout << a++;
cout << ++a;
}
Ans: b. In second 1 In first 2
13)Consider the following class hierarchy:
class Base
{
}
class Derived : private Base
{
}
Which of the following are true?
Ans: d. Derived can access public and protected member functions of Base
14)Consider the sample code given below and answer the question that follows.
class A
{
public:
A() {}
~A()
{
cout << "in destructor" << endl;
}
};
void main()
{
A a;
a.~A();
}
How many times will "in destructor" be output when the above code is compiled and executed?
Ans: d. A compile time error will be generated because destructors cannot be called directly
15)Consider the sample code given below and answer the question that follows.
class SomeClass
{
int x;
public:
SomeClass (int xx) : x(xx) {}
};
SomeClass x(10);
SomeClass y(x);
What is wrong with the sample code above?
Ans: e. The code will compile without errors
16)A pure virtual function can be declared by _______.
Ans: b. equating it to 0
17)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: d. foo = new char*[200];
18)Consider the following code:
class BaseException
{
public:
virtual void Output()
{ cout << "Base Exception" << endl; }
};
class DerivedException : public BaseException
{
public:
virtual void Output() { cout << "Derived Exception" << endl; }
};
void ExceptionTest()
{
try
{
throw DerivedException();
}
catch (BaseException& ex)
{
ex.Output();
}
catch (...)
{
cout << "Unknown Exception Thrown!" << endl;
}
}
Invoking Exception Test will result in which output?
Ans: b. Derived Exception
19)Which of the following is a function that returns a non zero value to indicate an I/O stream error?
Ans: h. None of the above
20)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: e. None of the above
21)What will be the output of the following code?
#include
using namespace std;
class b
{
int i;
public:
void vfoo()
{ cout <<"In Base "; }
};
class d : public b
{
int j;
public:
void vfoo()
{
cout<<"In Derived ";
}
};
void main()
{
b *p, ob;
d ob2;
p = &ob;
p->vfoo();
p = &ob2;
p->vfoo();
ob2.vfoo();
}
Ans: In Base In Base In Derived
22)Which of the following statements about constructors and destructors are true?
Ans: c. Constructors can take parameters, but destructors cannot
e. It is illegal to define a constructor as virtual
23)Consider the following class hierarchy:
class Base
{
}
class Derived : public Base
{
}
Which of the following are true?
Ans: d. Derived can access public and protected member functions of Base
e. The following line of code is valid: Base *object = new Derived();
24)Consider the sample code given below and answer the question that follows.
template Run;
Which one of the following is an example of the sample code given above?
Ans: c. A template function declaration
25)Consider the sample code given below and answer the question that follows.
class X {
int i;
protected:
float f;
public:
char c;
};
class Y : private X { };
Referring to the sample code above, which of the following data members of X are accessible from class Y
Ans: a. c
b. f
26)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: c. Only 1 and 2 are true
27)Which of the following operators cannot be overloaded?
a. +=
b. >>
c. <
d. .
e. ::
f. &&
g. =
h. ?:
Ans: d. .
e. ::
h. ?:
28)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: d. Person(const Person &p);
29)State which of the following is true.
a. Function templates in C++ are used to create a set of functions that apply the same algorithm to different data types
b. Classes in C++ are used to develop a set of type-safe classes
c. C++ is useful for developing collection classes
d. C++ is useful for developing smart pointers
e. All of the above
Ans: e. All of the above
30)Which of the following statements regarding functions are false?
a. Functions can be overloaded
b. Functions can return the type void
c. Inline functions are expanded during compile time to avoid invocation overhead
d. You can create arrays of functions
posted by khalequzzaman
e. You can pass values to functions by reference arguments
f. You can return values from functions by reference arguments
g. A function can return a pointer
Ans: d. You can create arrays of functions
31)Which of the following techniques should you use to handle a constructor that fails?
a. Return an error code from the constructor
b. Throw an exception from the constructor
c. Write the error to a log file
d. Use "delete this;" in the constructor
e. None of the above
Ans: b. Throw an exception from the constructor
32)What access specifier allows only the class or a derived class to access a data member
a. private
b. protected
c. default
d. virtual
e. public
Ans: b. protected
33)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: d. 7
34)Which of the following are NOT valid C++ casts
a. dynamic_cast
b. reinterpret_cast
c. static_cast
d. const_cast
e. void_cast
Ans: e. void_cast
35)Consider the following code:
class BaseException
{
public:
virtual void Output()
{
cout << "Base Exception" << endl;
}
};
class DerivedException : public BaseException
{
public:
virtual void Output()
{
cout << "Derived Exception" << endl;
}
};
void ExceptionTest()
{
try
{
throw DerivedException();
}
catch (BaseException ex)
{
ex.Output();
}
catch (...)
{
cout << "Unknown Exception Thrown!" << endl;
}
}
posted by khalequzzaman
Invoking Exception Test will result in which output?
Ans: a. Base Exception
36)Which of the following is NOT a standard sorting algorithm:
a. std::sort
b. std::qsort
c. std::stable_sort
d. std::partial_sort
Ans: b. std::qsort
37)How many arguments can be passed to an overloaded binary operator?
a. 4
b. 3
c. 2
d. 1
e. 0
Ans: d. 1
38)Which of the following is a predefined object in C++ and used to insert to the standard error output?
a. std::err
b. std::error
c. std::cerror
d. std::cerr
e. std::cin
f. std::clog
Ans: d. std::cerr
39)Which of the following statements are true?
a. Inline functions should be preferred over macros because inline functions have better performance
b. Macro usage should be avoided because they are error prone
c. Normal functions should be preferred over macros because normal functions have better performance
d. Macro usage should be avoided because macros do no perform type checking
e. Inline functions should be preferred over macros because inline functions perform type checking
Ans: b. Macro usage should be avoided because they are error prone
d. Macro usage should be avoided because macros do no perform type checking
e. Inline functions should be preferred over macros because inline functions perform type checking
40)Consider the sample code given below and answer the question that follows.
class Outer
{
public:
class Inner
{
int Count;
public:
Inner(){};
};
};
int main()
{
Inner innerObject;
Outer outObject;
return 0;
}
What will be the result when the above code is compiled?
Ans: d. There will be an error because in the declaration of innerObject the type Inner must be qualified by Outer
41)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?
Which of the following lines from the sample code above are examples of data member definition?
Ans: e. 19
42)What is the output of the following code segment?
int n = 9;
int *p;
p=&n;
n++;
cout << *p+2 << "," << n;
Ans: c. 12,10
43)Which of the following statements are FALSE with regard to destructors
a. A derived class can call the destructor of the parent class explicitly
b. A class may have only one destructor
c. Destructors cannot be invoked directly
d. The return type for a destructor is void
e. Destructors cannot accept arguments
Ans: a. A derived class can call the destructor of the parent class explicitly
43)If a matching catch handler (or ellipsis catch handler) cannot be found for the current exception, then the following predefined runtime function is called ______.
a. abort
b. set_terminate
c. terminate
d. close
Ans: c. terminate
44)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: e. monthTable winter,spring={"March","April","May"};
45)What happened when the following code is compiled and executed?
#include
using namespace std;
class myclass
{
private:
int number;
public:
myclass()
{
number = 2;
}
int &a()
{
return number;
}
};
int main()
{
myclass m1,m2;
m1.a() = 5;
m2.a() = m1.a();
cout<
return 0;
}
Ans: b. The printed output will be 5
46)Which of the following member functions can be used to add an element in an std::vector?
a. add
b. front
c. push
d. push_back
Ans: a. add
47)Which of the following techniques should you use to handle a destructor that fails?
a. Return an error code from the destructor
b. Throw an exception from the destructor
c. Write the error to a log file
d. Use "delete this;" in the destructor
e. None of the above
Ans: c. Write the error to a log file
48)Which of the following are NOT valid C++ casts
a. dynamic_cast
b. reinterpret_cast
c. static_cast
d. const_cast
e. void_cast
Ans: e. void_cast
49)In C++, the keyword auto can be used for:
a. Automatic assignment of data to objects during instantiation
b. Automatic call of a function
c. Declaration of a local variable
d. Automatically erasing an object when it is no longer needed
e. Automatic handling of run-time errors in the program
f. Automatic termination of a program in case the user does not respond within a given time period
g. Automatic creation of variables
Ans: c. Declaration of a local variable
50)Which of the following statements are true for operator overloading in C++?
a. The * operator can be overloaded to perform division
b. The * operator can be overloaded to perform assignment
c. ** can be overloaded to perform "to the power of"
d. Operators can be overloaded only in inside classes
e. Operators can be overloaded globally
Ans: a. The * operator can be overloaded to perform division
b. The * operator can be overloaded to perform assignment
c. ** can be overloaded to perform "to the power of"
d. Operators can be overloaded only in inside classes
51)State whether True or False.
Unary operator, overloaded by means of a friend function take one reference argument.
Ans: a. True
52)If input and output operations have to be performed on a file, an object of the _______ class should be created.
a. fstream
b. iostream
c. ostream
d. istream
e. None
Ans: a. fstream
#include
using namespace std;
int main()
{
cout << "The value of __LINE__ is " <<__LINE__;
return 0;
}
What will be the result when the above code is compiled and executed?
Ans: c. The code will compile and run without errors
2) Base class members are made accessible to a derived class and inaccessible to rest of the program by _____.
Ans: protected access specifier
3) Which of the following is not a standard STL header?
Ans: a.
4) Which of the following are true about class and struct in C++:
Ans: In a class all members are private by default, whereas in struct all members are public by default
5)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
6)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. A::I A::f() { return 0; }
b. A::I g(A::I p = A::x);
c. A::I g(A::I p) { return 0; }
d. A::I A::x = 0;
7)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: a. Yes, it is valid
8)Which of the following STL classes is deprecated (ie should no longer be used)
ostrstream
ostringstream
ostream
wostream
Ans: ostrstream
9)Which of the following statements are true about C++ vector class?
a. vector::empty deletes all elements of the vector
b. vector::erase can be used to delete a single element and a range of elements of the vector
c. After calling, vector::erase causes some of the iterators referencing the vector to become invalid
d. vector::count returns the number of elements in the vector
e. vector::size returns the number of elements in the vector
f. vector::capacity returns the number of elements in the vector
Ans: b. vector::erase can be used to delete a single element and a range of elements of the vector
c. After calling, vector::erase causes some of the iterators referencing the vector to become invalid
e. vector::size returns the number of elements in the vector
10)Consider the following code:
class BaseException
{
public:
virtual void Output()
{
cout << "Base Exception" << endl;
}
};
class DerivedException : public BaseException
{
public:
virtual void Output()
{
cout << "Derived Exception" << endl;
}
};
void ExceptionTest()
{
try
{
throw new DerivedException();
}
catch (DerivedException ex)
{
ex.Output();
}
catch (...)
{
cout << "Unknown Exception Thrown!" << endl;
}
}
Invoking Exception Test will result in which output?
Ans: c. Unknown Exception Thrown
11)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: b. Base Derived
12)What will be the output of the following code?
class A
{
public:
A():pData(0){}
~A(){}
int operator ++()
{
pData++;
cout << "In first ";
return pData;
}
int operator ++(int)
{
pData++;
cout << "In second ";
return pData;
}
private:
int pData;
};
void main()
{
A a;
cout << a++;
cout << ++a;
}
Ans: b. In second 1 In first 2
13)Consider the following class hierarchy:
class Base
{
}
class Derived : private Base
{
}
Which of the following are true?
Ans: d. Derived can access public and protected member functions of Base
14)Consider the sample code given below and answer the question that follows.
class A
{
public:
A() {}
~A()
{
cout << "in destructor" << endl;
}
};
void main()
{
A a;
a.~A();
}
How many times will "in destructor" be output when the above code is compiled and executed?
Ans: d. A compile time error will be generated because destructors cannot be called directly
15)Consider the sample code given below and answer the question that follows.
class SomeClass
{
int x;
public:
SomeClass (int xx) : x(xx) {}
};
SomeClass x(10);
SomeClass y(x);
What is wrong with the sample code above?
Ans: e. The code will compile without errors
16)A pure virtual function can be declared by _______.
Ans: b. equating it to 0
17)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: d. foo = new char*[200];
18)Consider the following code:
class BaseException
{
public:
virtual void Output()
{ cout << "Base Exception" << endl; }
};
class DerivedException : public BaseException
{
public:
virtual void Output() { cout << "Derived Exception" << endl; }
};
void ExceptionTest()
{
try
{
throw DerivedException();
}
catch (BaseException& ex)
{
ex.Output();
}
catch (...)
{
cout << "Unknown Exception Thrown!" << endl;
}
}
Invoking Exception Test will result in which output?
Ans: b. Derived Exception
19)Which of the following is a function that returns a non zero value to indicate an I/O stream error?
Ans: h. None of the above
20)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: e. None of the above
21)What will be the output of the following code?
#include
using namespace std;
class b
{
int i;
public:
void vfoo()
{ cout <<"In Base "; }
};
class d : public b
{
int j;
public:
void vfoo()
{
cout<<"In Derived ";
}
};
void main()
{
b *p, ob;
d ob2;
p = &ob;
p->vfoo();
p = &ob2;
p->vfoo();
ob2.vfoo();
}
Ans: In Base In Base In Derived
22)Which of the following statements about constructors and destructors are true?
Ans: c. Constructors can take parameters, but destructors cannot
e. It is illegal to define a constructor as virtual
23)Consider the following class hierarchy:
class Base
{
}
class Derived : public Base
{
}
Which of the following are true?
Ans: d. Derived can access public and protected member functions of Base
e. The following line of code is valid: Base *object = new Derived();
24)Consider the sample code given below and answer the question that follows.
template Run;
Which one of the following is an example of the sample code given above?
Ans: c. A template function declaration
25)Consider the sample code given below and answer the question that follows.
class X {
int i;
protected:
float f;
public:
char c;
};
class Y : private X { };
Referring to the sample code above, which of the following data members of X are accessible from class Y
Ans: a. c
b. f
26)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: c. Only 1 and 2 are true
27)Which of the following operators cannot be overloaded?
a. +=
b. >>
c. <
d. .
e. ::
f. &&
g. =
h. ?:
Ans: d. .
e. ::
h. ?:
28)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: d. Person(const Person &p);
29)State which of the following is true.
a. Function templates in C++ are used to create a set of functions that apply the same algorithm to different data types
b. Classes in C++ are used to develop a set of type-safe classes
c. C++ is useful for developing collection classes
d. C++ is useful for developing smart pointers
e. All of the above
Ans: e. All of the above
30)Which of the following statements regarding functions are false?
a. Functions can be overloaded
b. Functions can return the type void
c. Inline functions are expanded during compile time to avoid invocation overhead
d. You can create arrays of functions
posted by khalequzzaman
e. You can pass values to functions by reference arguments
f. You can return values from functions by reference arguments
g. A function can return a pointer
Ans: d. You can create arrays of functions
31)Which of the following techniques should you use to handle a constructor that fails?
a. Return an error code from the constructor
b. Throw an exception from the constructor
c. Write the error to a log file
d. Use "delete this;" in the constructor
e. None of the above
Ans: b. Throw an exception from the constructor
32)What access specifier allows only the class or a derived class to access a data member
a. private
b. protected
c. default
d. virtual
e. public
Ans: b. protected
33)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: d. 7
34)Which of the following are NOT valid C++ casts
a. dynamic_cast
b. reinterpret_cast
c. static_cast
d. const_cast
e. void_cast
Ans: e. void_cast
35)Consider the following code:
class BaseException
{
public:
virtual void Output()
{
cout << "Base Exception" << endl;
}
};
class DerivedException : public BaseException
{
public:
virtual void Output()
{
cout << "Derived Exception" << endl;
}
};
void ExceptionTest()
{
try
{
throw DerivedException();
}
catch (BaseException ex)
{
ex.Output();
}
catch (...)
{
cout << "Unknown Exception Thrown!" << endl;
}
}
posted by khalequzzaman
Invoking Exception Test will result in which output?
Ans: a. Base Exception
36)Which of the following is NOT a standard sorting algorithm:
a. std::sort
b. std::qsort
c. std::stable_sort
d. std::partial_sort
Ans: b. std::qsort
37)How many arguments can be passed to an overloaded binary operator?
a. 4
b. 3
c. 2
d. 1
e. 0
Ans: d. 1
38)Which of the following is a predefined object in C++ and used to insert to the standard error output?
a. std::err
b. std::error
c. std::cerror
d. std::cerr
e. std::cin
f. std::clog
Ans: d. std::cerr
39)Which of the following statements are true?
a. Inline functions should be preferred over macros because inline functions have better performance
b. Macro usage should be avoided because they are error prone
c. Normal functions should be preferred over macros because normal functions have better performance
d. Macro usage should be avoided because macros do no perform type checking
e. Inline functions should be preferred over macros because inline functions perform type checking
Ans: b. Macro usage should be avoided because they are error prone
d. Macro usage should be avoided because macros do no perform type checking
e. Inline functions should be preferred over macros because inline functions perform type checking
40)Consider the sample code given below and answer the question that follows.
class Outer
{
public:
class Inner
{
int Count;
public:
Inner(){};
};
};
int main()
{
Inner innerObject;
Outer outObject;
return 0;
}
What will be the result when the above code is compiled?
Ans: d. There will be an error because in the declaration of innerObject the type Inner must be qualified by Outer
41)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?
Which of the following lines from the sample code above are examples of data member definition?
Ans: e. 19
42)What is the output of the following code segment?
int n = 9;
int *p;
p=&n;
n++;
cout << *p+2 << "," << n;
Ans: c. 12,10
43)Which of the following statements are FALSE with regard to destructors
a. A derived class can call the destructor of the parent class explicitly
b. A class may have only one destructor
c. Destructors cannot be invoked directly
d. The return type for a destructor is void
e. Destructors cannot accept arguments
Ans: a. A derived class can call the destructor of the parent class explicitly
43)If a matching catch handler (or ellipsis catch handler) cannot be found for the current exception, then the following predefined runtime function is called ______.
a. abort
b. set_terminate
c. terminate
d. close
Ans: c. terminate
44)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: e. monthTable winter,spring={"March","April","May"};
45)What happened when the following code is compiled and executed?
#include
using namespace std;
class myclass
{
private:
int number;
public:
myclass()
{
number = 2;
}
int &a()
{
return number;
}
};
int main()
{
myclass m1,m2;
m1.a() = 5;
m2.a() = m1.a();
cout<
return 0;
}
Ans: b. The printed output will be 5
46)Which of the following member functions can be used to add an element in an std::vector?
a. add
b. front
c. push
d. push_back
Ans: a. add
47)Which of the following techniques should you use to handle a destructor that fails?
a. Return an error code from the destructor
b. Throw an exception from the destructor
c. Write the error to a log file
d. Use "delete this;" in the destructor
e. None of the above
Ans: c. Write the error to a log file
48)Which of the following are NOT valid C++ casts
a. dynamic_cast
b. reinterpret_cast
c. static_cast
d. const_cast
e. void_cast
Ans: e. void_cast
49)In C++, the keyword auto can be used for:
a. Automatic assignment of data to objects during instantiation
b. Automatic call of a function
c. Declaration of a local variable
d. Automatically erasing an object when it is no longer needed
e. Automatic handling of run-time errors in the program
f. Automatic termination of a program in case the user does not respond within a given time period
g. Automatic creation of variables
Ans: c. Declaration of a local variable
50)Which of the following statements are true for operator overloading in C++?
a. The * operator can be overloaded to perform division
b. The * operator can be overloaded to perform assignment
c. ** can be overloaded to perform "to the power of"
d. Operators can be overloaded only in inside classes
e. Operators can be overloaded globally
Ans: a. The * operator can be overloaded to perform division
b. The * operator can be overloaded to perform assignment
c. ** can be overloaded to perform "to the power of"
d. Operators can be overloaded only in inside classes
51)State whether True or False.
Unary operator, overloaded by means of a friend function take one reference argument.
Ans: a. True
52)If input and output operations have to be performed on a file, an object of the _______ class should be created.
a. fstream
b. iostream
c. ostream
d. istream
e. None
Ans: a. fstream
Subscribe to:
Posts (Atom)