Point out an error in the program. #include <iostream> using namespace std; int main() { char s1[] = "Hello"; char s2[] = "world"; char *const ptr = s1; *ptr = 'a'; ptr = s2; return 0; }
Answer(s): B,C
What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int x=20; int *ptr; ptr = &x; cout<<*ptr; 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 x=0; int *ptr; ptr = &x; cout<<x<<" "<<*ptr; return 0; }
Given: #include <iostream> #include <exception> using namespace std; int main () { try { int * myarray= new int[1000]; } catch (bad_alloc&) { cout << "Error allocating memory"; } catch (exception& e) { cout << "Standard exception"; } catch (...) { cout << "Unknown exception"; } return 0; }What will happen if we use the operator “new” and the memory cannot be allocated?
What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; struct { int x; char c; union { float f; int i; }; } s; int main (int argc, const char * argv[]) { s.x=10; s.i=0; cout << s.i << " " << s.x; }
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.