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;