Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Quiz Questions
    primarykey
    data
    text
    <p>I am practicing for an important quiz and I found 20 questions on c++ I am not very sure about. They came without answers and i wondered if you could help me answer them since I am still a rookie who is learning. I marked with an arrow the answer which i thought was correct for every wuestion with a brief reason.</p> <h3>QUESTION 1</h3> <pre><code>class Base{ protected: int a; public: void seta(int x){a = x;}; void printa(void){cout &lt;&lt; a;}; }; class SecondClass : public Base { public; int b; }; void main (void) { Secondclass tmp; tmp.seta(12); tmp.printa(); } a)SecondClass.a is public; b)SecondClass.a is protected; &lt;-- (Since SecondClass inherits from Base) c)SecondClass.a is private; d)SecondClass.a is not accessible; </code></pre> <h3>QUESTION 2</h3> <p>What happens when the function foo() below is executed? Assume bar() is an existing function.</p> <pre><code>void foo() { Object *o = new Object; bar(o); } a) o is destroyed at the end of the scope of foo b) o is not destroyed &lt;-- (since there is no delete and o is a pointer) c) o is destroyed if there is no exception in bar() d) None of the above </code></pre> <h3>QUESTION 3</h3> <p>Consider the following function declarations in a header file:</p> <pre><code>void doit(char *, int); int doit(char *); float doit(float, float); Which of the following declarations cannot follow in the same header (no idea): a) void doit(int, char*); b) float doit(char *); c) int doit(int, int); d) int doit(int); </code></pre> <h3>QUESTION 4</h3> <p>What is present in an abstract class that makes it abstract?</p> <pre><code>a) virtual keyword prefix o member function b) virtual keyword prefixed to member function and sufixed with =0 &lt;--(since without the =0 it wouldnt be a pure virtual method which must be overriden) c) member function in protected mode d) any of the above </code></pre> <h3>QUESTION 5</h3> <p>What is the result of the executing code fragment below?</p> <pre><code>//suitable #includes class Text { public: Text(const std::string &amp;text):data(new char[text.size()+1000]){ std::copy(text.begin(),text.end(),data); } ~Text(){ delete [] data; } void print() const{ std::cout &lt;&lt; data &lt;&lt; std::endl; } private: char *data; }; int main(int, char *[]) { Text outer("hello"); { const Text inner("world"); outer = inner; } outer.print(); return 0; } (No idea abou the answer) a) prints "world", but there is a buffer overflow in the constructor b) prints "world", no problems anywhere c) prints "hello" d) none of the above </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload