Free CPA Exam Braindumps (page: 8)

Page 8 of 56

What is the output of the program given below?

#include <iostream>

using namespace std;

int main (int argc, const char * argv[])
{
int i=10;
{
int i=0;
cout<<i;
}
{
i=5;
cout << i;
}
cout<<i;
return 0;
}

  1. 1010
  2. 101010
  3. 055
  4. None of these

Answer(s): C



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

#include <iostream>

using namespace std;

int main (int argc, const char * argv[])
{
int x,y;
union t
{
char tab[2];
int i;
};
union t u;
u.tab[0] = 1;
u.tab[1] = 2;
u.i = 0;
x = u.tab[0];
y = u.tab[1];
cout << x << "," << y << "," << u.i;
return 0;
}

  1. compilation fails
  2. It prints: 0,0,0
  3. It prints: 1,2,0
  4. None of these

Answer(s): B



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

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


class A {
protected:
int y;
public:
int x,z;
A() : x(1), y(2), z(0) { z = x + y; }
A(int a, int b) : x(a), y(b) { z = x + y;}
void Print() { cout << z; }
};


class B : public A {
public:
int y;
B() : A() {}
B(int a, int b) : A(a,b) {}
void Print() { cout << z; }
};


int main () {
A b;
b.Print();
return 0;
}

  1. It prints: 3
  2. It prints: 0
  3. It prints: 1
  4. It prints: 2

Answer(s): A



Which code, inserted at line 10, generates the output "Hello World"?

#include <iostream>
#include <string>
using namespace std;
string fun(string, string);
int main()
{
string s="Hello";
string *ps;
ps = &s;
//insert code here
return 0;
}


string fun(string s1, string s2)
{
return s1+s2;
}

  1. cout << fun(" World");
  2. cout << fun(*ps);
  3. cout << fun("Hello");
  4. cout << fun("Hello", " World");

Answer(s): D






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

CPA Exam Discussions & Posts