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

Page 23 of 65

What is the output of the program if characters 't', 'e', 's' and 't' enter are supplied as input?

#include <iostream>
#include <string>

using namespace std;

int main()
{
string s;
getline( cin, s );
cout << s << " " << s.length();
return( 0 );
}

  1. It prints: test 4
  2. It prints: test
  3. It prints: test 5
  4. It prints: 4

Answer(s): A



What happens if character 3 is entered as input?

#include <iostream>
using namespace std;
class A {
public:
int i;
};

int main () {
int c;
A obj;
obj.i = 5;
cin >> c;
try
{
switch (c)
{
case

  1. throw 20;
    case B. throw 5.2f;
    case C. throw obj;
    default: cout<<"No exception";
    }
    }
    catch (int e)
    { cout << "int exception. Exception Nr. " << e; }
    catch (A e)
    { cout << "object exception. Exception Nr. " << e.i; } catch (...)
    { cout << "An exception occurred."; }
    return 0;
    }
  2. It prints: object exception. Exception Nr. 5
  3. It prints: int exception. Exception Nr.
  4. It prints: An exception occurred
  5. It prints: No exception

Answer(s): A



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



Page 23 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