Free CPA-21-02 Exam Braindumps
CPA - C++ Certified Associate Programmer Questions 91–95 (page: 20)

Updated On: 9-Feb-2026

Point out an error in the program.

#include <iostream>
using namespace std;
int main()
{
char s1[] = "Hello";
char s2[] = "world";
char *const ptr = s1;
*ptr = 'a';
ptr = s2;
return 0;
}

  1. No error
  2. Cannot modify a const object
  3. Compilation error at line 9
  4. None of these

Answer(s): B,C



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

#include <iostream>

using namespace std;

int main()
{
int x=20;
int *ptr;
ptr = &x;
cout<<*ptr;
return 0;
}

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

Answer(s): A



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



Viewing page 20 of 53
Viewing questions 96 - 100 out of 257 questions


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

AI Tutor AI Tutor 👋 I’m here to help!