• entries
146
436
• views
198174

# C++ Quiz #4

1271 views

This is a test of your knowledge of C++, not of your compiler's knowledge of C++. Using a compiler during this test will likely give you the wrong answers, or at least incomplete ones.

1. What is the value of i after the first numbered line is evaluated?

2. What do you expect the second numbered line to print out?

3. What is the value of p->c after the third numbered line is evaluated?

4. What does the fourth numbered line print?

struct C;void f(C* p);struct C {    int c;    C() : c(1) {        f(this);    }};const C obj;void f(C* p) {    int i = obj.c << 2;             //1    std::cout<< p->c  << std::endl;   //2    p->c = i;                       //3    std::cout<< obj.c << std::endl; //4}

5. What should you expect the compiler to do on the first numbered line? Why?

6. What should you expect the value of j to be after the second numbered line is evaluated? Why?

struct X {    operator int() {        return 314159;    }};struct Y {    operator X() {        return X();    }};Y y;int i = y;     //1int j = X(y);  //2

7. What should you expect the compiler to do on the first and second numbered lines? Why?

struct Z {    Z() {}    explicit Z(int) {}};Z z1 = 1;                 //1Z z2 = static_cast<Z>(1); //2

8. What should you expect the behavior of each of the numbered lines, irrespective of the other lines, to be?

struct Base {    virtual ~Base() {}};struct Derived : Base {        ~Derived() {}};typedef Base Base2;Derived d;Base* p = &d;void f() {        d.Base::~Base();    //1    p->~Base();         //2        p->~Base2();        //3        p->Base2::~Base();  //4        p->Base2::~Base2(); //5}

Source

I realize that this was imported from your blog.

This one is easy. None of it even compiles. Done.

Where's my prize?

Yeah, the "new" editor is really great.

*sigh* fucking ... i don't even.

I mean REALLY?

Yup, really. No more HTML tags for, erm, three years now. Only BBCode.

Yup, really. No more HTML tags for, erm, three years now. Only BBCode.

This entry was imported from my blog. Apparently my choices for RSS import are either "Import everything completely fucked up and wrong." or "Import everything completely fucked up and wrong."

Reminds me of the South Park episode about a mascot election.

There are HTML to BBCode translators online - not very reliable, BBCode don't seem to be standardized, every page has different flavours. And I've yet to find the escape sequence working here :/

I don't think you quite understand.

This post was automatically imported from my blog.

I did not create this post (on this site).

I'm not going to bother editing it to fix it every single time it imports a post from my site.

Furthermore, it used to import them "just fine", with the exception of not properly handling formatting.

Hmmm, now I see it. That bug doesn't seem to be that old (your older blog entries from this year worked).

Yeah, such functionality should just work (you're not the only one using it). And there are years old issues with the editor. It's really a pity for a tech site like gamedev. No idea, why they don't get fixed.

Edit: Sorry for being off topic, this supposed to be about C++.