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; }
Answer(s): B
Point out an error in the program. #include <iostream> using namespace std; int main() { const int x=1; int const *y=&x; cout<<*y; return 0; }
Answer(s): A
What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int i=2; switch(i) { case 1: cout<<"Hello"; case 2: cout<<"world"; case 3: cout<<"End"; } return 0; }
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; double i=2; c1 = i; c1.print(); return 0; }
Answer(s): D
What happens when you attempt to compile and run the following code? #include <iostream> #include <string> using namespace std; int f(int i, int b); int main() { int i=0; i++; for (i=0; i<=2; i++) { cout<<f(0,i); } return 0; } int f(int a, int b) { return a+b; }
Post your Comments and Discuss C++ Institute CPA exam prep with other Community members:
Our website is free, but we have to fight against AI bots and content theft. We're sorry for the inconvenience caused by these security measures. You can access the rest of the CPA content, but please register or login to continue.