[C ++ Quiz] Intermediate Level

Source: Internet
Author: User
Question 1

Can you name the special functions a C ++ compiler can create implicitly?
Tip answer
Question 2

What are the two ways to achieve automatic type conversion from Type X to Type Y?
Tip answer
Question 3

Which of one of these represents an assignment operation?

  1. C C1 = c2;
  2. C3 = C4;
  3. Both

Tip answer
Question 4

Given the classQz4:

class Qz4 {enum{ arr_l=5 };int *arr; // array of intint seed;char *name;public:Qz4(char *str, int i) : name(str), seed(i) {arr = new int[arr_l];for(int i=0;i<arr_l;arr[i]=seed + i++);}~Qz4() {delete [] arr;cout << "arr destroyed for " << name << endl;}void print_arr() {cout << name << ":" << endl;for(int i=0;i<arr_l;i++) cout << "Element #" << i << "=" << get_arr(i) << endl;}void set_arr(int idx, int val) {arr[idx]=val;}int get_arr(int idx) {return arr[idx];}};

Can you predict the output of the program below?

int main() {Qz4 q1("Q1",0), q2("Q2",10);q2=q1;q1.set_arr(0, 32);q2.set_arr(1, 56);q1.print_arr();q2.print_arr();}

Answer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.