CPP

CPP

Resource Management has 9 Questions
What can go wrong in resource management on c++?

Leakage
Exhaustion
Dangling
All of the mentioned
When we call that resource is leaked?

Arise of compile time error
It cannot be accessed by any standard mean.
Arise of runtime error
none of the mentioned
What kind of error can arise when there is problem in memory?

Segmentation fault
Produce an error
Both a & b
none of the mentioned
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         int i, n;
  7.         int * p;
  8.         i = 2;
  9.         p= new (nothrow) int[i];
  10.         if (p == 0)
  11.             cout << "Error: memory could not be allocated";
  12.         else
  13. 	{
  14.             for (n=0; n<i; n++)
  15.             {
  16.                 p[n] = 5;
  17.             }
  18.             for (n = 0; n < i; n++)
  19.                 cout << p[n];
  20.             delete[] p;
  21.          }
  22.          return 0;
  23.     }

5
55
555
Error: memory could not be allocated
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     int main(void)
  4.     {
  5.         const char *one = "Test";
  6.         cout << one << endl;
  7.         const char *two = one;
  8.         cout << two << endl;
  9.         return 0;
  10.     }

Test
TestTest
Te
none of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     int funcstatic(int)
  4.     {
  5.         int sum = 0;
  6.         sum = sum + 10;
  7.         return sum;
  8.     }
  9.     int main(void)
  10.     {
  11.         int r = 5, s;
  12.         s = funcstatic(r);
  13.         cout << s << endl;
  14.         return 0;
  15.     }

10
15
error
none of the mentioned
What is meant by garbage collection?

Form of manual memory management
Form of automatic memory management
Used to replace the variables
None of the mentioned
What are the operators available in dynamic memory allocation?

new
delete
compare
both a & b
Which is used to solve the memory management problem in c++?

Smart pointers
arrays
stack
none of the mentioned