Some questions:
Personal blog: http://muscle1990.com /? P = 84
1. Briefly describe the memory segments of the C/C ++ program during compilation.
- STACK: the stack zone is automatically allocated and released by the compiler, and stores the parameter values and local variables of the function. Its operation is similar to the stack in the data structure;
- Heap zone: It is generally allocated and released by programmers. If the programmer does not release it, the program will be withdrawn by the operating system at the end. Note that it is similar to the heap in the data structure. The allocation method is similar to the linked list;
- Global zone (static zone): stores global variables and static variables in this zone. initialized global variables are in one region, uninitialized in another region, and the system recycles them;
- Text constant area: the constant string is here, and the end is withdrawn by the system;
- Code area: stores the binary code of a function;
2. When is multithreading good during programming and when is it highly efficient to use a single thread?
Operations or computations that can only be executed in serial mode can only be performed in a single thread;
For services with short processing time or high startup frequency, use a single thread. On the contrary, use multiple threads!
No matter when a single thread can be used, multithreading is not required.
When a concurrent operation is allowed and the operation may be blocked, use multiple threads, such as socket and disk operations.
3. Talking about JVM garbage collection
A notable feature of Java is the introduction of the garbage collection mechanism, which helps C ++ programmers solve the most troublesome memory management problems, it makes memory management unnecessary for Java programmers when writing programs. Because of the garbage collection mechanism, objects in Java do not have the concept of "Scope", and only objects can be referenced with "Scope ". Garbage collection can effectively prevent memory leakage and effectively use available memory. The garbage collector is usually used as a separate low-level thread to clear and recycle objects that have died or are not used in the memory heap for a long time, programmers cannot call the Garbage Collector to recycle an object or all objects in real time. The collection mechanism involves generational replication, garbage collection, marking, and incremental garbage collection.
Java Programmers don't have to worry about memory management, because the Garbage Collector automatically manages. To request garbage collection, you can call one of the following methods:
System. GC ()
Runtime. getruntime (). GC ()
For more information, click Java garbage collection.
4. Differences between sizeof and strlen (pick the wrong question)
- Sizeof is an operator and strlen is a library function.
- The sizeof parameter can be a data type or variable, while strlen can only be a parameter with a string ending with '\ 0.
- The compiler calculates the sizeof result during compilation, and the strlen function can only be computed at runtime, and sizeof calculates the memory size of the data type, the actual length of the string calculated by strlen.
- The sizeof parameter of the array is not degraded. If it is passed to strlen, It is degraded to a pointer.
- The result types of sizeof and strlen are both size_t.
5. Write a "standard" macro Min? (Write a "standard" macro min, which inputs two parameters and returns a smaller one)
# Define min (I, j) (I) <= (j )? (I) :( J ))
// Point: parentheses are required for the variable.
6. Convert the hexadecimal value to the 2-10hexadecimal value;
#include <iostream>using namespace std;int ans,temp;int rec(int n,int m){for(ans=0,temp=1;n/m!=1;){temp=temp*10;n=n/m;ans+=(n%m)*temp;}ans +=temp*10;return ans;}int main(){int num;num =rec(28,2);cout<<num<<endl;return 0;}
7. Calculate the maximum subarray and
A lot of Baidu... Greedy algorithms are the most convenient