Free CPA Exam Braindumps (page: 4)

Page 3 of 56

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

#include <iostream>

using namespace std;

int main()
{
float x=3.5,y=1.6;
int i,j=2;
i = x + j + y;
cout << i;
return 0;
}

  1. It prints: 7
  2. It prints: 6
  3. It prints: 7,1
  4. Compilation error

Answer(s): A



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

#include <iostream>
using namespace std;

int main(){
int i = 1;
if (i==1) {
cout << i;
} else {
cout << i-1;
}
return 0;
}

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

Answer(s): B



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

#include <iostream>
#include <string>

using namespace std;

class complex{
double re, im;
public:
complex() : re(1),im(0.4) {}
complex operator+(complex &t);
void Print() { cout << re << " " << im; }
};


complex complex::operator+ (complex &t){
complex temp;
temp.re = this?>re + t.re;
temp.im = this?>im + t.im;
return temp;
}


int main(){
complex c1,c2,c3;
c3 = c1 + c2;
c3.Print();
}

  1. It prints: 1 0.4
  2. It prints: 2 0.8
  3. It prints: 0 0
  4. Garbage value

Answer(s): B



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

#include <cstdlib>
#include <iostream>

using namespace std;

float* sum(float a,float b);

float* sum(float a,float b)
{
float *f = new float;
*f = a+b;
return f;
}

int main()
{
float a,b,*f;
a = 1.5; b = 3.4;
f = sum(a,b);
cout<<*f;

return 0;
}

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

Answer(s): B






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

CPA Discussions & Posts