What is the output of following program?


			  		

Loading

Practice Memory Management –

What is the output of following program?

#include 
using namespace std;

class Player
{
private:
int id;
static int next_id;
public:
int getID() { return id; }
Player() { id = next_id++; }
};
int Player::next_id = 1;

int main()
{
Player p1;
Player p2;
Player p3;
cout << p1.getID() << " ";
cout << p2.getID() << " ";
cout << p3.getID();
return 0;
}

What is the output of following program?


			  		

Loading

Practice Memory Management –

What is the output of following program?

#include 
using namespace std;

class Test
{
static int x;
public:
Test() { x++; }
static int getX() {return x;}
};

int Test::x = 0;

int main()
{
cout << Test::getX() << " ";
Test t[5];
cout << Test::getX();
}

Find the output of following program?


			  		

Loading

Practice Memory Management –

Find the output of following program?

#include 
class Test
{
public:
void fun();
};
static void Test::fun()
{
std::cout<<"fun() is static ";
}
int main()
{
Test::fun();
return 0;
}

Predict the output of following program.


			  		

Loading

Practice Memory Management –

Predict the output of following program.

#include
using namespace std;

class Test
{
private:
static int count;
public:
Test& fun();
};

int Test::count = 0;

Test& Test::fun()
{
Test::count++;
cout << Test::count << " ";
return *this;
}

int main()
{
Test t;
t.fun().fun().fun().fun();
return 0;
}

How “Late binding” is implemented in C++?

Loading

Practice Memory Management –

How “Late binding” is implemented in C++?

If we create a file by ‘ifstream’, then the default mod

Loading

Practice Memory Management –

If we create a file by ‘ifstream’, then the default mode of the file is ______________.

To perform stream I/O with disk files in C++, you should

Loading

Practice Memory Management –

To perform stream I/O with disk files in C++, you should

An array element is accessed using

Loading

Practice Memory Management –

An array element is accessed using

If an array is declared as
int a[4] = {3, 0, 1, 2}, then values

Loading

Practice Memory Management –

If an array is declared as
int a[4] = {3, 0, 1, 2}, then values assigned to a[0] & a[4] will be ________. 

In C++, dynamic memory allocation is accomplished with the operator

Loading

Practice Memory Management –

In C++, dynamic memory allocation is accomplished with the operator ____________.

Which of the following jobs are NOT performed by a

Loading

Practice Memory Management –

Which of the following jobs are NOT performed by a Garbage Collector?

  1. Freeing memory on the stack.
  2. Avoiding memory leaks.
  3. Freeing memory occupied by unreferenced objects.
  4. Closing unclosed database collections.
  5. Closing unclosed files.