Keyword

Result: 265 questions

What value does size print out?

#include <iostream>

const int SIZE = 5;

struct tester
{
    int array[SIZE];

    enum 
    {
        SIZE = 3
    };

    void size()
    {
        std::cout << sizeof(array) / sizeof(int);
    }
};

int main(int argc, char** argv)
{
    tester t;
    t.size();
    return 0;
}
Quiz

What value does foo print out?

#include <iostream>

const int SIZE = 5;

struct tester
{
    void foo()
    {
        std::cout << SIZE << std::endl;
    }

    enum 
    {
        SIZE = 3
    };
};

int main(int argc, char** argv)
{
    tester t;
    t.foo();
    return 0;
}
Quiz

Which of the following functions are found when called in main during name lookup?

#include <iostream>

namespace standards
{
    struct datastructure
    {
    };

    void foo(const datastructure& ds)
    {
    }

    void bar()
    {
    }
}

int main(int argc, char** argv)
{
    standards::datastructure ds;

    foo(ds);

    bar();

    return 0;
}
Quiz

Which lines of code below should not compile?

1  struct Foo
2  {
3  };
4 
5  struct Bar
6  {
7  };
8 
9 
10 int main()
11 {
12     Foo* f = new Foo;
13 
14     Bar* b1 = f;
15     Bar* b2 = static_cast<Bar*>(f);
16     Bar* b3 = dynamic_cast<Bar*>(f);
17     Bar* b4 = reinterpret_cast<Bar*>(f);
18     Bar* b5 = const_cast<Bar*>(f);
19 
20     return 0;
21 }
Quiz

Which lines of code below should cause the program to be undefined?

 1 struct Foo
 2 {
 3   virtual ~Foo() {}
 4 };
 5
 6 struct Bar : public Foo
 7 {
 8 };
 9
10 int main(int argc, char** argv)
11 {
12   Foo* f = new Bar;
13   delete f;
14   f = 0;
15   delete f;
16
17   Foo* fa = new Bar[10];
18   delete [] fa;
19   fa = 0;
20   delete fa;
21
22   return 0;
23 }
Quiz

Will "Hello World" be printed by the program below?

struct Foo
{
  int x;
  int y;
};

int main(int argc, char** argv)
{
  Foo f;

  if ( &f.x < &f.y )
  {
    std::cout << "Hello World" << std::endl;
  }

  return 0;
}
Quiz

True or False, the program below will print NOT EQUAL

#include <iostream>

struct Foo
{
};

struct Bar 
{
};

int main(int argc, char** argv)
{
  Foo* f = new Foo;
  Bar* b = new Bar;

  if ( f == b )
    std::cout << "EQUAL" << std::endl;
  else
    std::cout << "NOT EQUAL" << std::endl;

  return 0;
}
Quiz

What value gets printed by the program?

#include <iostream>

struct Foo
{
  int x;

  operator int()
  {
    return 21;
  }
};

int main(int argc, char** argv)
{
  Foo f;
  f.x = 11;

  std::cout << (0?3:f) << std::endl;

  return 0;
}
Quiz

What value gets printed by the program?

#include <iostream>

struct Foo
{
  Foo(int d) : x(d) {}
  int x;
};

int main() 
{ 
  double x = 3.14;

  Foo f( int(x) );

  std::cout << f.x << std::endl;

  return 0;
}
Quiz

Which, if any, of the member function definitions below are ill-formed?

#include <iostream>

int g_x = 44; 

struct Foo 
{ 
  int m_x; 

  static int s_x; 

  Foo(int x) : m_x(x) {} 

  int a(int x = g_x) 
  { 
    return x + 1; 
  } 

  int b(int x = m_x) 
  { 
    return x + 1; 
  } 

  int c(int x = s_x) 
  { 
    return x + 1; 
  } 
}; 

int Foo::s_x = 22; 

int main(int argc, char** argv) 
{ 
  Foo f(6); 

  std::cout << f.a() << std::endl; 
  std::cout << f.b() << std::endl; 
  std::cout << f.c() << std::endl; 

  return 0; 
}
Quiz

What is the output of the program?

#include <iostream>

struct A 
{ 
  virtual int foo(int x = 5) 
  { 
    return x * 2; 
  } 
}; 

struct B : public A 
{ 
  int foo(int x = 10) 
  { 
    return x * 3; 
  } 
}; 

int main(int argc, char** argv) 
{ 
  A* a = new B; 

  std::cout << a->foo() << std::endl; 

  return 0; 
}
Quiz

What is the output of the program?

#include <iostream>

struct BS
{
  unsigned int color;
};

struct car : public BS
{
};

struct truck : public BS
{
};

struct city : public car, public truck
{
};

int main(int argc, char** argv) 
{ 
  city c;

  c.color = 3;

  std::cout << c.color << std::endl;

  return 0; 
}
Quiz

How many times is Hello World printed by this program?

#include <iostream>

struct BS
{
  BS()
  {
    std::cout << "Hello World" << std::endl;
  }
  unsigned int color;
};

struct mid1 : virtual public BS { };
struct mid2 : virtual public BS { };
struct mid3 : public BS { };
struct mid4 : public BS { };

struct DR : public mid1, public mid2, 
            public mid3, public mid4 { };

int main(int argc, char** argv) 
{ 
  DR d;
  return 0; 
}
Quiz

What gets printed by this program?

#include <iostream>

struct Shape
{
  void print()
  {
    std::cout << "SHAPE" << std::endl;
  }
};

struct Box : public Shape
{
  void print()
  {
    std::cout << "BOX" << std::endl;
  }
};

int main(int argc, char** argv)
{
  Shape* s1 = new Box;

  s1->print();

  return 0;
}
Quiz

What gets printed by this program?

#include <iostream>

struct Shape
{
  virtual void print()
  {
    std::cout << "SHAPE" << std::endl;
  }
  virtual ~Shape() {}
};

struct Box : public virtual Shape
{
  void print()
  {
    std::cout << "BOX" << std::endl;
  }
};

struct Sphere : public virtual Shape
{
  void print()
  {
    std::cout << "SPHERE" << std::endl;
  }
};

struct GeoDisc : public Box, public Sphere
{
};

int main(int argc, char** argv)
{
  Shape* s = new GeoDisc;

  s->print();

  delete s;

  return 0;
}
Quiz

How many times is Hello World printed by this program?

#include <iostream>

struct BS
{
  BS()
  {
    std::cout << "Hello World" << std::endl;
  }
};

struct mid1 : public BS { };
struct mid2 : public BS { };
struct mid3 : public BS { };
struct mid4 : public BS { };

struct DR : public virtual mid1, public virtual mid2, public virtual mid3, public mid4 { };

int main(int argc, char** argv) 
{ 
  DR d;
  return 0; 
}

 

Quiz

What gets printed by this program?

#include <iostream>

struct Shape
{
  virtual void print()
  {
    std::cout << "SHAPE" << std::endl;
  }

  virtual ~Shape() {}
};

struct Box : public Shape
{
  virtual void print(int i)
  {
    std::cout << "BOX" << std::endl;
  }
};

int main(int argc, char** argv) 
{ 
  Shape* s = new Box;

  s->print();

  delete s;

  return 0; 
}
Quiz

What gets printed by this program?

#include <iostream>

struct Shape
{
  virtual Shape* duplicate()
  {
    std::cout << "SHAPE" << std::endl;
    return new Shape;
  }
  virtual ~Shape() {}
};

struct Box : public Shape
{
  virtual Box* duplicate()
  {
    std::cout << "BOX" << std::endl;
    return new Box;
  }
};

int main(int argc, char** argv) 
{ 
  Shape* s1 = new Box;

  Shape* s2 = s1->duplicate();

  delete s1;
  delete s2;
  return 0; 
}
Quiz

What gets printed by this program?

#include <iostream>

struct Shape
{
  virtual Shape* duplicate()
  {
    return new Shape;
  }
  virtual void print()
  {
    std::cout << "SHAPE" << std::endl;
  }
  virtual ~Shape() {}
};

struct Box : public Shape
{
  virtual Box* duplicate()
  {
    return new Box;
  }
  virtual void print()
  {
    std::cout << "BOX" << std::endl;
  }
};

int main(int argc, char** argv) 
{ 
  Shape* s1 = new Box;

  Box* b1 = s1->duplicate();

  b1->print();

  delete s1;
  delete b1;
  return 0; 
}
Quiz

What gets printed by this program?

#include <iostream>

struct Shape
{
  virtual void print()
  {
    std::cout << "SHAPE" << std::endl;
  }
  virtual ~Shape() {}
};

struct Box : private Shape
{
  virtual void print()
  {
    std::cout << "BOX" << std::endl;
  }
};

int main(int argc, char** argv) 
{ 
  Shape* s = new Box;

  s->print();

  delete s;

  return 0; 
}
Quiz

© 2017 QuizBucket.org