Sail E0 Webinar

MCQs

Total Questions : 10
Question 1.

Which is used to solve the memory management problem in c++?


  1.    Smart pointers
  2.    arrays
  3.    stack
  4.    none of the mentioned
 Discuss Question
Answer: Option A. -> Smart pointers

None.


Question 2.

What are the operators available in dynamic memory allocation?


  1.    new
  2.    delete
  3.    compare
  4.    both a & b
 Discuss Question
Answer: Option D. -> both a & b

new and delete operators are mainly used to allocate and deallocate
during runtime.


Question 3.

What is meant by garbage collection?


  1.    Form of manual memory management
  2.    Form of automatic memory management
  3.    Used to replace the variables
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> Form of automatic memory management

The garbage collectoion attempts to reclaim memory occupied by objects that are no longer in use 

by the program.


Question 4.


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
int main()
5.
{
6.
try
7.
{
8.
char *p;
9.
strcpy(p, "How r u");
10.
}
11.
catch(const exception& er)
12.
{
13.
}
14.
}
  1.    How r u
  2.    segmentation fault
  3.    error
  4.    runtime error
 Discuss Question
Answer: Option B. -> segmentation fault

As we are using a pointer value to copy a string, So it will be producing a runtime error.
Output:
$ g++ res3.cpp
$ a.out
segmentation fault


Question 5.


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
  1.    10
  2.    15
  3.    error
  4.    none of the mentioned
 Discuss Question
Answer: Option A. -> 10

Eventhough we passed the value, we didn't caught to manipulate it, So it is printing as 10.
Output:
$ g++ res2.cpp
$ a.out
10



Question 6.


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
  1.    Test
  2.    TestTest
  3.    Te
  4.    none of the mentioned
 Discuss Question
Answer: Option B. -> TestTest

We are copying the values from one variable to other, So it is printing is TestTest
Output:
$ g++ res1.cpp
$ a.out
TestTest


Question 7.

What can go wrong in resource management on c++?


  1.    Leakage
  2.    Exhaustion
  3.    Dangling
  4.    All of the mentioned
 Discuss Question
Answer: Option D. -> All of the mentioned

If there is any mishap in memory or resource management means, the problems that are mentioned 

above can happen.


Question 8.

When we call that resource is leaked?


  1.    Arise of compile time error
  2.    It cannot be accessed by any standard mean.
  3.    Arise of runtime error
  4.    none of the mentioned
 Discuss Question
Answer: Option B. -> It cannot be accessed by any standard mean.

Resource is said to be leaked when it cannot by accessed by any means of standard mean.


Question 9.

What kind of error can arise when there is problem in memory?


  1.    Segmentation fault
  2.    Produce an error
  3.    Both a & b
  4.    none of the mentioned
 Discuss Question
Answer: Option A. -> Segmentation fault

None


Question 10.


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
  1.    5
  2.    55
  3.    555
  4.    Error: memory could not be allocated
 Discuss Question
Answer: Option B. -> 55

As we had given i value as 2, It will print the 5 for two times.
Output:
$ g++ res.cpp
$ a.out
55


Latest Videos

Latest Test Papers