Question 2#
Which of the following statements about the program below are true?
True |
|
|---|---|
Statement A |
|
Statement B |
|
Statement C |
|
Statement D |
|
Statement E |
Statement A
The output of the following program run is empty, and the exit status is 0.
$ ./example2 0 $ echo $? 0
Statement B
(Abbreviated; meaning the output and exit status are as shown)
$ ./example2 1 Foo() bar() ~Foo() $ echo $? 0
Statement C
(…)
$ ./example2 need one parameter $ echo $? 0
Statement D
The program has a memory leak
Statement E
The program’s behavior is undefined
#include <iostream>
#include <string>
class Foo
{
public:
Foo() {
std::cout << "Foo()" << std::endl;
}
~Foo() {
std::cout << "~Foo()" << std::endl;
}
void bar() const {
std::cout << "bar()" << std::endl;
}
};
int main(int argc, char** argv)
{
Foo* f = nullptr;
if (argc != 2) {
std::cerr << "need one parameter" << std::endl;
return 1;
}
int i = std::stoi(argv[1]);
if (i)
f = new Foo;
if (i)
f->bar();
if (i)
delete f;
return 0;
}