Free CPA-21-02 Exam Braindumps (page: 24)

Page 24 of 65

What happens when you attempt to compile and run the following code?

#include <iostream>

using namespace std;

int main()
{
int x=0;
int *ptr;

ptr = &x;
cout<<x<<" "<<*ptr;

return 0;
}

  1. It prints: 0 0
  2. It prints address of ptr
  3. It prints: 1
  4. It prints: 2

Answer(s): A



Given:

#include <iostream>
#include <exception>
using namespace std;

int main () {
try
{
int * myarray= new int[1000];
}
catch (bad_alloc&)
{
cout << "Error allocating memory";
}
catch (exception& e)

{
cout << "Standard exception";
}
catch (...)
{
cout << "Unknown exception";
}
return 0;
}

What will happen if we use the operator "new" and the memory cannot be allocated?

  1. It prints: Error allocating memory
  2. It prints: Standard exception
  3. It prints: Unknown exception
  4. Compilation error

Answer(s): A



What happens when you attempt to compile and run the following code?

#include <iostream>

using namespace std;

struct {
int x;
char c;
union {
float f;
int i;
};
} s;

int main (int argc, const char * argv[])
{

  1. x=10;
  2. i=0;
    cout << s.i << " " << s.x;
    }
  3. It prints: 0 10
  4. It prints: 11
  5. Compilation error
  6. None of these

Answer(s): A



What is the output of the program?

#include <iostream>
#include <string>

using namespace std;

int main () {
string s1 = "Hello", s2 = "World";
s2 = s1 + s2;
cout << s2;
return 0;
}

  1. It prints: Hello
  2. It prints: HelloWorld
  3. It prints: WorldHello
  4. It prints: WorldHelloWorld

Answer(s): B



Page 24 of 65



Post your Comments and Discuss C++ Institute CPA-21-02 exam with other Community members:

Subash commented on October 21, 2024
I am planning to take this exam. Are these 257 questions enough to clear it? Also, does each section have a passing percentage, or is it based on the overall ?
INDIA
upvote