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

Page 31 of 65

What is the output of the program?

#include <iostream>

using namespace std;

#define SQR(x)(x*x)

int main(int argc, char *argv[]) {
int x, y=2;

x = SQR(y);
cout << x << ", " <<y;
return 0;
}

  1. It prints: 3, 2
  2. It prints: 4, 2
  3. It prints: 3, 3
  4. It prints: 9, 2

Answer(s): B



What will be the output of the program?

#include <iostream>

using namespace std;

int main()
{
int i=0;
for(; i<=5; i++)
cout << i;

return 0;
}

  1. 012345
  2. 0123
  3. 5
  4. 6

Answer(s): A



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

#include <iostream>
using namespace std;

class Base {
int age;
public:
class C {
int b;
void PrintC() { cout << b; }
};
Base () {age=5;};
void setAge(int a=20) {age = a;}
void Print() { cout << age;}
};

int main () {
Base a;

  1. setAge(10);
  2. Print();
    return 0;
    }
  3. It prints: 1020
  4. It prints: 105
  5. It prints: 10
  6. It prints: 20

Answer(s): C



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

#include <iostream>
using namespace std;
class complex{
double re;
double im;
public:
complex() : re(0),im(0) {}
complex(double x) { re=x,im=x;};
complex(double x,double y) { re=x,im=y;}
void print() { cout << re << " " << im;}
};

int main(){
complex c1;
c1.print();
return 0;
}

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

Answer(s): C






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

Exam Discussions & Posts