C ++ questions (9)

Source: Internet
Author: User

1. Describe the use of the static keyword in the following example:
①Static int A = 100;

② Static int func_1 (INT iparam)
{
...
}

③ Int func_2 (INT iparam)
{
Static int B = 0;
...
};

④ Class ca
{
Static int C;
Static int func_3 (INT iparam );
...
};

2. Describe the usage of the const keyword in the following example:

① Const int d = 100;
Const char * pstr_0 = "ABCD ";
Char * const pstr_1 = "ABCD ";

② Class CB
{
Int func_4 (INT iparam) const;
Int func_5 (INT iparam );
...
};

3. Which of the following statements are invalid in the implementation of func_4?
Int CB: func_4 (INT iparam) const
{
D ++;
Int * Pd = & D;
* PD ++;

Pstr_0 [0] = 0;
Pstr_0 = pstr_1;

Pstr_1 [0] = 0;
Pstr_1 = pstr_0;

...
}

4. Memory application and release

// Describe the similarities and differences between the two methods for applying for memory
// Method 1
Int * P1;
P1 = malloc (sizeof (INT) * 100 );
// Method 2
Int * P2;
P2 = new int [100];

5. What are the similarities and differences between the following two methods of applying for memory?
Struct _ St
{
Int;
Int B;
...
} * St_1, * ST_2
// Method 1
St_1 = malloc (sizeof (_ st) * 100 );
// Method 2
ST_2 = new _ st [100];

6. What are the similarities and differences between the following two methods of applying for memory?
Class ca
{
Public:
CA ();
~ CA ();
...
} * CA_1, * ca_2
// Method 1
CA_1 = malloc (sizeof (CA) * 100 );
// Method 2
Ca_2 = new Ca [100];

 

7. What are the similarities and differences between the following methods to release memory?
Int * P;
P = new int [100];
// Method 1
Free (P );
// Method 2
Delete P;
// Method 3
Delete [] P;

 

 

8. How do I release memory in the following ways?
Class ca
{
Public:
CA ();
~ CA ();
...
} * PCA;
PCA = new Ca [100];
// Method 1
Free (PCA );
// Method 2
Delete PCA;
// Method 3
Delete [] PCA;

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.