C++ Institute CPA-21-02 - Questions & Answers
Free preview · every answer includes a full explanation
Product page: https://prepkeys.com/cpa-21-02.html
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
void set(struct person*);
struct person
{int age;
};
int main()
{struct person e = {18};
set(&e);
cout<< e.age;
return 0;
}
void set(struct person *p)
{p?>age = p?>age + 1;
}
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{int x=2, *y, z=3;
y = &z;
cout<<x**y*x***y;
return 0;
}
What is the output of the program?
#include <iostream>
using namespace std;
int main()
{int tab[4]={10,20,30,40};
tab[1]=10;
int *p;
p=&tab[0];
cout<<*p;
return 0;
}
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
int x;
protected:
int y;
public:
int z;
A() { x=1; y=2; z=3; }
};
class B : public A {
string z;
public:
void set() {
y = 4;
z = "John";
}
void Print() {
cout << y << z;
}
};
int main () {
B b;
b.set();
b.Print();
return 0;
}
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
public:
int x;
A() { x=0;}
};
class B {
public:
int x;
B() { x=1;}
};
class C :public A, public B {
public:
int x;
C(int x) {
this?>x = x;
A :x = x + 1;
}
void Print() { cout << x << A::x << B::x; }
};
int main () {
C c2(1);
c2.Print();
return 0;
}
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;
}
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{int x=2, *y;
y = &x;
cout << *y + x;
return 0;
}
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{int x=0;
int *ptr;
ptr = &x;
cout<<x<<" "<<*ptr;
return 0;
}
Which of the following statements are correct about an array?
int tab[10];
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class First
{string *s;
public:
First() { s = new string("Text");}
~First() { delete s;}
void Print(){ cout<<*s;}
};
int main()
{First FirstObject;
FirstObject.~First();
}