1. Is a parent class having written a virtual function? Can a sub-class overwrite its function without the virtual function realize polymorphism?
Virtual modifiers are implicitly inherited. Private is also integrated, but the derived class has no access permission. Virtual instances can be added or not added. All variables of the parent class (except static) exist in the space of the Child class ). Only one entity exists in a function (except inline ). The sub-class can also implement polymorphism without adding virtual to its function. In the subclass space, there are private variables of the parent class. Private variables cannot be accessed directly.
--------------------------------------------------------------------------
2. Enter a string and output it in reverse order. (C ++ is used, and pseudo code is not recommended)
# Include <iostream>
Using namespace STD;
Void main ()
{
Char A [50]; memset (A, 0, sizeof ());
Int I = 0, J;
Char T;
Cin. Getline (A, 50, '/N ');
For (I = 0, j = strlen (a)-1; I <strlen (a)/2; I ++, j --)
{
T = A [I];
A [I] = A [J];
A [J] = T;
}
Cout <A <Endl;
}
// Type 2
String STR;
Cin> STR;
Str. Replace;
Cout <STR;
--------------------------------------------------------------------------
3. Briefly describe the Windows Memory Management Method.
Memory Management is an important part of the operating system. I am afraid no one can make it clear in two or three sentences ~~
Let me give you a rough idea. I hope you can give me some advice.
When running the program, you need to read the code of this program from the memory. The location of the Code must be in the physical memory before it can be run. Because there are a lot of programs running in the operating system, the memory cannot be completely put down, so the concept of virtual memory is introduced. Puts unused program fragments into the virtual memory. When you need to use them, load them into the primary memory (physical memory. This is what memory management needs to do. Another thing needs to be done for memory management: the physical location of the computing program fragment in the primary memory for CPU scheduling.
Memory Management includes block-Based Management, page-based management, and segment-based page management. Common segment Page Management
Block management: divides the primary storage into one large block and one large block. When the required program fragments are not in the primary storage, a primary storage space is allocated and the Sequential parts are loaded into the primary storage, even if only a few bytes are needed, the program can only be allocated to it. This will cause a lot of waste, with an average waste of 50% of the memory space, but it is easy to manage.
Page Management: The primary storage is divided into one page and one page. The space on each page is much smaller than one page. Obviously, the space utilization of this method is much higher than that of 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, however, it also has another disadvantage. A program segment may be divided into dozens of segments, so much time will be wasted on computing the physical address of each segment (I/O is the most time-consuming computer ).
Segment-and-Page Management: combines the advantages of segment-And page-based management. The primary storage is divided into several pages, each of which is divided into several sections. The benefits are obvious. I don't need to say more.
Various memory management methods are used to calculate the physical addresses of program fragments in the primary memory. In fact, they are similar.
This is just a rough idea. It is not enough to explain the knowledge of memory management. No matter which operating system book has a detailed explanation
--------------------------------------------------------------------------
4.
# 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;
}
What is the result of this question?
Define is just a definition. in programming, it is just a simple replacement of x * X. It does not go through arithmetic rules.
A/= (k + M) * (K + M)/(K + M) * (K + M );
=> A/= (k + M) * 1 * (K + M );
=> A = A/9;
=> A = 1;
--------------------------------------------------------------------------
5.
Const symbol constant;
(1) const char * P
(2) Char const * P
(3) char * const P
The differences described above are described;
If the const is on the left side of the asterisk, the const is used to modify the variable pointed to by the pointer, that is, the pointer points to a constant;
If const is on the right side of the asterisk, const modifies the pointer itself, that is, the pointer itself is a constant.
Const char * P; // same as char const * P
Char const * P; // pointer to a constant. The constant value cannot be changed.
Char * const P; // constant pointer. The value of P cannot be modified.
--------------------------------------------------------------------------
6. below are two if statement judgment methods in C language. Which of the following statements is better? Why?
Int N;
If (n = 10) // the first judgment method
If (10 = N) // method 2
If a = sign is missing, an error will be reported during compilation, which reduces the number of rows that may cause an error and can be detected if = is missing.
--------------------------------------------------------------------------
7. 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 );
No space for P is released, causing memory leakage.
--------------------------------------------------------------------------
8. What is the problem with the following code? Provide the correct statement.
Void dosomething (char * P)
{
Char STR [16];
Int N;
Assert (null! = P );
Sscanf (P, "% S % d", STR, N );
If (0 = strcmp (STR, "something "))
{
...
}
}
A:
Sscanf (P, "% S % d", STR, n); this sentence is written as: sscanf (P, "% S % d", STR, & N );
--------------------------------------------------------------------------
9. What are the following code errors?
Void test1 ()
{
Char string [10];
Char * str1 = "0123456789 ";
Strcpy (string, str1 );
}
Array out-of-bounds
--------------------------------------------------------------------------
10. What is the problem with the following code?
Void Test2 ()
{
Char string [10], str1 [10];
For (I = 0; I <10; I ++)
{
Str1 [I] = 'a ';
}
Strcpy (string, str1 );
}
Array out-of-bounds
--------------------------------------------------------------------------
11. What is the problem with the following code?
Void test3 (char * str1)
{
Char string [10];
If (strlen (str1) <= 10)
{
Strcpy (string, str1 );
}
}
= Array out-of-bounds
= The End mark of strcpy copy is to find/0 in the string. Therefore, if/0 is not encountered in the string, it will be copied until/0 is encountered, and the above 123 is out of bounds.
We recommend that you use strncpy and memcpy.
--------------------------------------------------------------------------
12. What is the problem with the following code?
# Define max_srm 256
DSN get_srm_no ()
{
Static int srm_no; // isn't the initial value assigned here?
Int I;
For (I = 0; I <max_srm; I ++, srm_no ++)
{
Srm_no % = max_srm;
If (my_srm.state = idle)
{
Break;
}
}
If (I> = max_srm)
Return (null_srm );
Else
Return srm_no;
}
The system initializes the static int variable to 0, but the value is always saved. The so-called non-reentrant...
--------------------------------------------------------------------------
13. Write the running result:
{// Test1
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;
}
6: 4: 1: 4
--------------------------------------------------------------------------
14. Write the running result:
{// Test2
Union v {
Struct X {
Unsigned char S1: 2;
Unsigned char S2: 3;
Unsigned char S3: 3;
} X;
Unsigned char C;
} V;
V. C = 100;
Printf ("% d", V. X. S3 );
}
3
--------------------------------------------------------------------------
15. How can I determine whether an operating system is a 16-bit or 32-bit program written in C ++? The sizeof () function cannot be used.
A1:
In a 16-bit system,
Int I = 65536;
Cout <I; // output 0;
Int I = 65535;
Cout <I; // output-1;
In a 32-bit system,
Int I = 65536;
Cout <I; // output 65536;
Int I = 65535;
Cout <I; // output 65535;
A2:
Int A = ~ 0;
If (A> 65536)
{
Cout <"32 bit" <Endl;
}
Else
{
Cout <"16 bit" <Endl;
}
--------------------------------------------------------------------------
16. What is the difference between C ++ and C ++?
Mechanism: C is process-oriented (but C can also write Object-oriented Programs); C ++ is object-oriented and provides classes. However,
C ++ is easier to write object-oriented programs than C
From the applicable direction: C is suitable for scenarios that require small code size and high efficiency, such as embedded; C ++ is suitable for upper-level and complex; llinux is mostly written in C, because it is system software, the efficiency requirement is extremely high.
From the name, we can see that C ++ is more + than C, which means C ++ is the superset of C. Why is C ++ not called C ++, because of the C ++ Ratio
C, there are too many extended things, so I put two + s behind C, so it became C ++
C is a structured programming language, and C ++ is an object-oriented programming language.
C ++ focuses on objects rather than processes, and on class design rather than logic design.
--------------------------------------------------------------------------
17. Switch the values of two parameters without using third-party parameters.
# Include <stdio. h>
Void main ()
{
Int I = 60;
Int J = 50;
I = I + J;
J = I-j;
I = I-j;
Printf ("I = % d/N", I );
Printf ("J = % d/N", J );
}
Method 2:
I ^ = J;
J ^ = I;
I ^ = J;
Method 3:
// Use addition and subtraction without Overflow
A = a + B-(B =)
--------------------------------------------------------------------------
18. Questions about bit domains (why is the output a strange character)
A. t = 'B'; the effect is equivalent to a. t = 'B' & 0xf;
'B' --> 01100010
'B' & 0xf -- & gt; 00000010
Therefore, the output ASCII code is a special character of 2.
Char T: 4; is a 4-bit character variable, the same
Unsigned short I: 8; is the 8-bit unsigned short integer variable.
--------------------------------------------------------------------------
19. Int I = 10, j = 10, K = 3; K * = I + J; what is the final value of K?
60
--------------------------------------------------------------------------
20. What are the methods for inter-process communication?
Inter-process communication methods include shared memory, pipelines, sockets, message queues, and DDE.
--------------------------------------------------------------------------
21.
Struct
{
Char T: 4;
Char K: 4;
Unsigned short I: 8;
Unsigned long m;
}
Sizeof (A) =? (Boundary alignment is not considered)
7
Struct cell // declare cell Bit Field
{
Unsigned character: 8; // 00000000 ????????
Unsigned Foreground: 3; // 00000 ??? 00000000
Unsigned intensity: 1; // 0000? 000 00000000
Unsigned Background: 3; // 0 ??? 0000 00000000
Unsigned Blink: 1 ;//? 0000000 00000000
} Screen [25] [80]; // array of bit Fields
Ii. Bit Structure
The bit structure is a special structure. When you need to access Multiple Digits of one byte or word by bit, the bit structure
It is more convenient than the bitwise operator.
The bit structure is defined as follows:
Struct bit structure name {
Data type variable name: integer constant;
Data type variable name: integer constant;
}-Bit structure variable;
Where: the data type must be int (unsigned or signed ). Integer constants must be non-negative integers.
Number in the range of 0 ~ 15 indicates the number of binary bits, that is, the number of bits.
The variable name is a selection item and can be left unspecified. This is required for arrangement.
For example, a single-digit structure is defined below.
Struct {
Unsigned Incon: 8;/* Incon occupies a low byte of 0 ~ 8 digits in total */
Unsigned txcolor: 4;/* txcolor occupies 0 ~ 3 digits, 4 digits in total */
Unsigned bgcolor: 3;/* bgcolor occupies 4 ~ 6 digits, 3 digits in total */
Unsigned Blink: 1;/* blink occupies 7th bytes */
} Ch;
The access of the bitwise structure member is the same as that of the structure member.
For example, to access the bgcolor member in the structure of the above sample bit, you can write it as follows:
Ch. bgcolor
Note:
1. The Members in the bit structure can be defined as unsigned or signed, but when the member length is
When the degree is 1, it is considered as the unsigned type. Because a single bit cannot have symbols.
2. The members in the bit structure cannot use arrays and pointers, but the bit structure variables can be arrays and pointers,
If it is a pointer, its member access method is the same as the structure pointer.
3. The total length (number of digits) of the bit structure is the sum of the digits defined by each bit member and can exceed two characters
Section.
4. A structure member can be used with other structure members.
For example:
Struct info {
Char name [8];
Int age;
Struct ADDR address;
Float pay;
Unsigned state: 1;
Unsigned pay: 1;
} Workers;
The structure of the above example defines information about a worker. There are two bitwise structure members.
The constructor has only one member, so it only occupies one byte but stores two pieces of information. The first part of this Byte indicates
The second digit indicates whether the salary has been paid. The bit structure can save storage space.
--------------------------------------------------------------------------
22. The following function adds a number to a fixed number. What are the errors and corrections?
Int add_n (int n)
{
Static int I = 100;
I + = N;
Return I;
}
A:
Because static makes the I value retain the previous value.
Remove static.
--------------------------------------------------------------------------
23. What is the problem with the following code?
Class
{
Public:
A () {P = This ;}
~ A () {If (P! = NULL) {Delete P; P = NULL ;}}
A * P;
};
A:
Will cause infinite Recursion
--------------------------------------------------------------------------
24.
Union {
Int a_int1;
Double a_double;
Int a_int2;
};
Typedef struct
{
A A1;
Char y;
} B;
Class C
{
Double c_double;
B B1;
A A2;
};
Output The cout <sizeof (c) <Endl; result?
A:
In the vc6 environment, the result is 32.
In addition:
I (Sun) tested it in vc6.0 + Win2k:
Short-2
Int-4
Float-4
Double-8
Pointer-4
Sizeof (union), with the largest size in the structure as the Union size
----------------------------------------------------------------------------------
25. What is the last I equal?
Int I = 1;
Int J = I ++;
If (I> J ++) & (I ++ = J) I + = J;
A:
I = 5
--------------------------------------------------------------------------
26.
Unsigned short array [] = {1, 2, 3, 4, 5, 6, 7 };
Int I = 3;
* (Array + I) =?
A:
4
--------------------------------------------------------------------------
27.
Class
{
Virtual void func1 ();
Void func2 ();
}
Class B: Class
{
Void func1 () {cout <"fun1 in Class B" <Endl ;}
Virtual void func2 () {cout <"fun2 in Class B" <Endl ;}
}
Both func1 and func2 in A and A are virtual functions.
Func1 and func2 in B, A are not virtual functions.
C. func2 in a is a virtual function. func1 in B is not a virtual function.
D. func2 in a is not a virtual function, and func1 in B is a virtual function.
A:
A
--------------------------------------------------------------------------
28.
Database: extracts the Department and average salary. The database is ordered by the Department string and cannot contain "human resource" department,
The structure of the employee is as follows: employee_id, employee_name, depart_id, depart_name, wage
A:
Select depart_name, AVG (wage)
From employee
Where depart_name <> 'human resource'
Group by depart_name
Order by depart_name
--------------------------------------------------------------------------
29.
Given the following sqldatabase: Test (Num int (4), use an SQL statement to return the minimum value of num, but do not use the statistical function, such as min or Max.
A:
Select top 1 num
From Test
Order by num DESC
--------------------------------------------------------------------------
30.
Output The following program results.
# Include <iostream. h>
Class
{
Public:
Virtual void print (void)
{
Cout <"A: Print ()" <Endl;
}
};
Class B: public
{
Public:
Virtual void print (void)
{
Cout <"B: Print ()" <Endl;
};
};
Class C: Public B
{
Public:
Virtual void print (void)
{
Cout <"C: Print ()" <Endl;
}
};
Void print ()
{
A. Print ();
}
Void main (void)
{
A A, * pA, * pb, * PC;
B;
C;
Pa = &;
PB = & B;
PC = & C;
A. Print ();
B. Print ();
C. Print ();
Pa-> Print ();
Pb-> Print ();
PC-> Print ();
Print ();
Print (B );
Print (C );
}
A:
A: Print ()
B: Print ()
C: Print ()
A: Print ()
B: Print ()
C: Print ()
A: Print ()
A: Print ()
A: Print ()
--------------------------------------------------------------------------
31.
Write a function to determine whether the byte storage order of a computer is in the ascending order (little endian) or descending order (bigendian)
A:
Bool isbigendian ()
{
Unsigned short usdata = 0x1122;
Unsigned char * pucdata = (unsigned char *) & usdata;
Return (* pucdata = 0x22 );
}
--------------------------------------------------------------------------
32. Differences between the critical section and mutex
A:
Summary of several synchronization objects
1. Critical Section
A. Fast
B. It cannot be used in different processes.
C. Resource statistics are not allowed (only one thread can access Shared resources at a time)
2. mutex
A. Slow speed
B. It can be used in different processes.
C. Resource statistics are not allowed.
3. semaphore
A. Slow speed
B. It can be used in different processes.
C. Resource statistics (one or more threads can access Shared Resources)
4. Event
A. Slow speed
B. It can be used in different processes.
C. Resource statistics are available.
--------------------------------------------------------------------------
33. A database has two tables:
A table contains the customer field ID and name;
An order table contains the field ID, mermerid (foreign key that connects to the ID in customer), and revenue;
Write the SQL statement that calculates the total revenue of each customer.
Create a table
Create Table customer
(
Id int primary key, name char (10)
)
Go
Create Table [order]
(
Id int primary key, customerid int foreign key references customer (ID), revenue float
)
Go
-- Query
Select customer. ID, sum (isnull ([order]. Revenue, 0 ))
From customer full join [order]
On ([order]. customerid = Customer. ID)
Group by customer. ID
--------------------------------------------------------------------------
34. Indicate errors in the following programs and modify them
Void getmemory (char * P ){
P = (char *) malloc (100 );
}
Void test (void ){
Char * STR = NULL;
Getmemory = (STR );
Strcpy (STR, "Hello World ");
Printf (STR );
}
A: Error -- if the parameter value is changed, it will not be returned.
Getmemory does not support dynamic memory. Str in the test function is always null.
Strcpy (STR, "Hello World"); will crash the program.
Modify as follows:
Char * getmemory (){
Char * P = (char *) malloc (100 );
Return P;
}
Void test (void ){
Char * STR = NULL;
STR = getmemory (){
Strcpy (STR, "Hello World ");
Printf (STR );
}
Method 2: void getmemory2 (char ** P) is changed to a second-level pointer.
Void getmemory2 (char ** P, int num)
{
* P = (char *) malloc (sizeof (char) * num );
}
--------------------------------------------------------------------------
35. program error correction
Class MML
{
PRIVATE:
Static unsigned int X;
Public:
MML () {x ++ ;}
MML (static unsigned Int &) {x ++ ;}
~ MML {X --;}
Pulic:
Virtual Mon () {}= 0;
Static unsigned int MMC () {return X ;}
......
};
Class NNL: Public MML
{
PRIVATE:
Static unsigned int y;
Public:
NNL () {x ++ ;}
NNL (static unsigned Int &) {x ++ ;}
~ NNL {X --;}
Public:
Virtual Mon (){};
Static unsigned int NNC () {return y ;}
......
};
Code snippet:
MML * PP = new NNL;
..........
Delete pp;
A:
The destructor of the base class should be virtual functions.
Virtual ~ MML {X --;}
--------------------------------------------------------------------------
36.101 coins: 100 real, 1 fake, the difference between true and false lies in the weight. Please give the conclusion of whether the real coin is heavy or the fake coin is heavy twice without the weight.
A:
Take out 2 heaps of 101 first,
33,33
If they are not equal for the first time, there is a pile of heavy or light
Take the heavy heap down and put it in 33 of the other 35.
If the values are equal, it indicates that the values are false. If the values are not equal and the values are new, it indicates that the values are false (the values cannot be new)
For the first time, if they are equal, these 66 items must be true. Take 35 out of these 66 items and compare them with the 35 others that have not been called.
Needless to say
Method 2:
You can compare question 3rd with question a (50) and question B (50). In the same case, compare the remaining question with the actual question.
If they are different, use a bunch of them. For example, if a (50) is divided into two heaps and 25 for comparison
In B (50), the difference is in a (50), combined with the first result will be known.
--------------------------------------------------------------------------
37. What are the characteristics of static variables and functions?
A:
Static variables: they remain valid during the running period. If they are defined outside the function, they are visible within the compilation unit. If they are within the function, they are visible within the defined block;
Static function: visible in the compilation unit;
--------------------------------------------------------------------------
38. Use C to write an input integer. Use a recursive method to return the output integer;
A:
Void fun (int)
{
Printf ("% d", a % 10 );
A/= 10;
If (A <= 0) return;
Fun ();
}
--------------------------------------------------------------------------
39. Write the program results:
Void func (char STR [1, 100])
{
Printf ("% d/N", sizeof (STR ));
}
A:
4
Analysis:
Pointer Length
--------------------------------------------------------------------------
40. Int ID [sizeof (unsigned long)];
Is that correct? Why ??
A:
Pair
This sizeof is the compile-time operator, which is determined during compilation.
It can be viewed as a machine-related constant.