Q: Is a parent class having written a virtual function? Can a sub-class overwrite its function without the virtual function realize polymorphism?
A:
Virtual modifiers are implicitly inherited. Virtual can be added or not added. The subclass space contains all the variables of the parent class (except static), and the same function only has one entity (except inline ), the sub-class can also implement polymorphism without adding virtual to its function.
Bytes ------------------------------------------------------------------------------------------
Q: enter a string and output it in reverse order. (C ++ is used, and pseudo code is not recommended)
A:
# Include <iostream>
# Include <string>
Using namespace STD;
Int main ()
{
Char * src = "Hello World ";
Int Len = 0;
Char * DEST = new char;
While (* SRC ++! = NULL)
{
Cout <* (src-1 );
}
Src-= 2;
Cout <Endl;
While (* SRC --! = NULL)
{
* DEST = * (SRC + 1 );
Cout <* DEST;
* DEST ++;
}
Cout <Endl;
Return 0;
}
Bytes ------------------------------------------------------------------------------------------
Q: Write the program result:
Void func (char STR [1, 100])
{
Printf ("% d/N", sizeof (STR ));
}
A: 4
Analysis: pointer Length
Bytes ------------------------------------------------------------------------------------------
Q: How to manage Windows Memory?
A: Windows Memory Management mainly handles two tasks:
1. Put the uncommonly used program fragments into the virtual memory and load them into the primary memory when necessary.
2. computing program segments are physically located in the primary storage for CPU calls.
Memory Management includes block management, Page Management, segment management, and segment Page Management.
Block management: divides the primary storage into a large block. When the required program fragments are not in the primary storage, a primary storage space is allocated to load the program fragments into the primary storage, even if the required program fragment contains only a few bytes, this part can only be allocated to it. This will cause a lot of waste. On average, 50% of the memory space is wasted, but it is easy to manage.
Page Management: divides the primary storage into one page. The space on each page is much smaller than that on one page. Obviously, this method is much more efficient than block management.
Segment management: the primary storage is divided into segments. The space of each segment is much smaller than that of one page. This method is much higher than page management in terms of space utilization, but there is also a disadvantage. A program segment may be divided into dozens of segments, which wastes a lot of time computing each segment of physical address.
Segment-and-Page Management: combines the advantages of segment-And page-based management. The primary storage is divided into several pages and each page is divided into several sections. This not only makes the space utilization efficient, but also increases the speed of accessing the physical address.
Bytes ------------------------------------------------------------------------------------------
Q: Do I need to use a recursive method to write an input integer in C and return the function of the output integer?
A:
# Include <iostream>
# Include <string>
Using namespace STD;
Void fun (int)
{
Cout <a % 10;
A/= 10;
If (A <= 0)
Return;
Fun ();
}
Int main ()
{
Int input_data;
Cout <"enter an integer :";
Cin> input_data;
Fun (input_data );
Return 0;
}
Bytes ------------------------------------------------------------------------------------------
Q: What are the output results of the following programs?
# Include "stdafx. H"
# Define sqr (x) x * x
Int main (INT argc, char * argv [])
{
Int A = 10;
Int K = 2;
Int M = 1;
A/= sqr (K + M)/sqr (K + M );
Printf ("% d/N", );
Return 0;
}
A: 1
Explanation:
Sqr (K + M)/sqr (K + M)
= K + M * k + M/K + M * k + m
= 2 + 1*2 + 1/2 + 1*2 + 1
= 2 + 2 + 0 + 2 + 1
= 7
A = A/7 = 1
Bytes ------------------------------------------------------------------------------------------
Q: const symbol constant;
(1) const char * P
(2) Char const * P
(3) char * const P
(4) const char * const P
The differences described above are described;
A:
(1) const char * P is a pointer to a constant type. The value to which the Pointer Points cannot be changed, but the pointer can point to other variables.
(2) Char const * P is a pointer to a constant type. The value to which the Pointer Points cannot be changed, but the pointer can point to other variables.
(3) char * const P is a constant pointer to the struct type. The value to which the Pointer Points can be changed, but the pointer cannot point to other variables.
(4) const char * const P is a constant pointer to a constant type constant. The value to which the Pointer Points cannot be changed, and the pointer cannot point to other variables.
Note:
Const "before" * indicates that the content remains unchanged.
Const after "*" indicates that the pointer remains unchanged.
Bytes ------------------------------------------------------------------------------------------
Q: The following are two if statement judgment methods in C. Which of the following statements is better? Why?
Int N;
If (n = 10) // the first judgment method
If (10 = N) // method 2
A: Second Type
If one "=" is missing, the compiler will detect the error. if the first one is missing, the compiler will not prompt an error.
Bytes ------------------------------------------------------------------------------------------
Q: What is the problem with the following code?
Void dosomething (...)
{
Char * P;
...
P = malloc (1024); // allocate 1 K space
If (null = P)
Return;
...
P = realloc (p, 2048); // The space is not enough and is allocated to 2 k again.
If (null = P)
Return;
...
}
A:
P = malloc (1024); It should be written as: P = (char *) malloc (1024 );
Char * P = NULL; initialize.
The "stack memory" pointer automatically disappears at the end of return, but it does not mean that the memory space of P is released, which may cause memory leakage.
Bytes ------------------------------------------------------------------------------------------
Q: Enter the if statement for comparing bool, float, pointer variables with "zero value.
Tip: here, the "zero value" can be 0, 0.0, false, or "Null Pointer ". For example, the IF statement for the comparison between int Variable N and zero value is:
If (n = 0)
If (n! = 0)
And so on.
Write the if statement for comparing bool flag with zero value:
Write the if statement for comparing float X with "zero value:
Write the if statement for comparing char * P with "zero value:
A:
Write the if statement for comparing bool flag with zero value:
If (FLAG)
If (! Flag)
The following statement is not a good style with no score
If (flag = true)
If (flag = 1)
If (flag = false)
If (flag = 0)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Write the if statement for comparing float X with "zero value:
Const float epsinon = 0.00001
If (x> =-epsinon) & (x <= epsinon ))
The following is a wrong statement, with no score
If (x = 0.0)
If (X! = 0.0)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Write the if statement for comparing char * P with "zero value:
If (P = NULL)
If (P! = NULL)
The following statement is not a good style with no score
If (P = 0)
If (P! = 0)
If (P)
If (!)
Bytes ------------------------------------------------------------------------------------------
Q: The following is a 32-bit C ++ program in Windows NT. Calculate the sizeof value.
Char STR [] = "hello ";
Char * P = STR;
Int n = 10;
Calculate
Sizeof (STR) =
Sizeof (p) =
Sizeof (n) =
Void func (char STR [1, 100])
{
Calculate
Sizeof (STR) =
}
Void * P = malloc (100 );
Calculate
Sizeof (p) =
A:
Char STR [] = "hello ";
Char * P = STR;
Int n = 10;
Calculate
Sizeof (STR) = 6;
Sizeof (p) = 4;
Sizeof (n) = 4;
Void func (char STR [1, 100])
{
Calculate
Sizeof (STR) = 4;
}
Void * P = malloc (100 );
Calculate
Sizeof (p) = 4;
Bytes ------------------------------------------------------------------------------------------
Q: What is the use of ifdef/define/endif in the header file?
A: Pre-compile the command to prevent the header file from being repeatedly referenced.
Bytes ------------------------------------------------------------------------------------------
Q: What is the difference between # include <FILENAME. h> and # include "filename. H?
A:
For # include <FILENAME. h>, the compiler searches for filename. h from the standard library path.
For # include "filename. H", the compiler searches for filename. h from the user's working path.
Bytes ------------------------------------------------------------------------------------------
Q: What is the purpose of const? (Please specify at least two types)
A:
1. Const constants can be defined.
2. const can modify function parameters, return values, and even function definitions. Things modified by const are strongly protected, which can prevent unexpected changes and improve program robustness.
Bytes ------------------------------------------------------------------------------------------
Q: Why should I add the extern "C" statement to call the function compiled by the C compiler in the C ++ program?
A:
C ++ supports function overloading, while C does not. The name of the function in the library after being compiled by C ++ is different from that in C language.
Assume that the prototype of a function is void Foo (int x, int Y );
The name of this function in the library compiled by the C compiler is _ Foo, while the C ++ compiler generates names such as _ foo_int_int.
C ++ provides a C connection exchange with the specified symbol extern "c" to solve the name matching problem.
Bytes ------------------------------------------------------------------------------------------
Q: Write the running result:
Int main ()
{
Char STR [] = "world"; cout <sizeof (STR) <":";
Char * P = STR; cout <sizeof (p) <":";
Char I = 10; cout <sizeof (I) <":";
Void * PP = malloc (10); cout <sizeof (p) <Endl;
}
A:
Char STR [] = "world"; cout <sizeof (STR) <":"; 6
Char * P = STR; cout <sizeof (p) <":"; 4
Char I = 10; cout <sizeof (I) <":"; 1
Void * PP = malloc (10); cout <sizeof (p) <Endl; 4