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

Page 28 of 65

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

#include <iostream>
using namespace std;
int main()
{
const int x=20;
const int *ptr;
ptr = &x;
*ptr = 10;
cout<<*ptr;
return 0;
}

  1. It prints: 20
  2. It prints: 10
  3. Compilation error at line 8
  4. It prints address of ptr

Answer(s): C



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;
}
{
int i=5;

cout << i;
}
cout<<i;
return 0;
}

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

Answer(s): C

Explanation:



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

#include <iostream>

using namespace std;

class First
{
public:
void Print(){ cout<<"from First";}
};
class Second
{
public:
void Print(){ cout<< "from Second";}
};
int main()
{

Second t[2];
for (int i=0; i<2; i++)
t[i].Print();
}

  1. It prints: from First
  2. It prints: from Firstfrom First
  3. It prints: from Secondfrom Second
  4. It prints: from Second

Answer(s): C



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

#include <iostream>

using namespace std;

void fun(int*);

int main()
{
int *x;
int i=2;
x=&i;
fun(x);
cout<<i;
return 0;
}

void fun(int *i)
{
*i = *i * *i;
}

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

Answer(s): B



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