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;
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;
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;}
Answer(s): D
What happens when you attempt to compile and run the following code?#include <iostream>using namespace std;int x=5;static int y=0;void myFunction(int a){y=++a;}int main (int argc, const char * argv[]){int i=0;myFunction(i);cout<<y<<" "<<x;}
Answer(s): C
What happens when you attempt to compile and run the following code?#include <iostream>using namespace std;class A {public:void Print(){ cout<<"A"; }};class B:public A {public:virtual void Print(){ cout<< "B"; }};class C:public B {public:void Print(){ cout<< "C"; }};int main(){A ob1;B ob2;C ob3;A *obj;obj = &ob1;obj?>Print();obj = &ob2;obj?>Print();obj = &ob3;obj?>Print();}
Post your Comments and Discuss C++ Institute CPA-21-02 exam prep with other Community members: