Jump to content
  • Advertisement
  • entries
  • comments
  • views

C++ Quiz #4

Sign in to follow this  


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) {

    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; //1
    int 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; //1
    Z 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

Sign in to follow this  


Recommended Comments

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."

Share this comment

Link to comment

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 :/

Share this comment

Link to comment
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.

Share this comment

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

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++.

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!