1, array a [N], stored 1 to the number of N-1, where a Number repeated once. Write a function to identify the time complexity of the repeated numbers. It must be an o (N) function prototype:
Int find (int a [], int n ){
Int temp [n] = {0 };
Int I;
For (I = 0; I <n; I ++ ){
If (temp [a [I]! = 0 ){
Return a [I];
} Else {
Temp [a [I] = 1;
}
}
}
2. A statement is used to determine whether x is a power of 2.
Int I = 512;
Cout <(I & (I-1 ))? False: true) <endl;
Bitwise AND operator a & B are reserved for the bit where B is 1. If a is also 1, all the other bits in a are set to 0, the remaining a is the result and can be understood as retaining the bits corresponding to the median 1 of B in a, and the remaining 0. The other bitwise operators are similar. bitwise operations are performed on a and B, and the resulting value is the result.
3,
Char str1 [] = "abc ";
Char str2 [] = "abc ";
Const char str3 [] = "abc ";
Const char str4 [] = "abc ";
Const char * str5 = "abc ";
Const char * str6 = "abc ";
Char * str7 = "abc ";
Char * str8 = "abc ";
Cout <(str1 = str2) <endl;
Cout <(str3 = str4) <endl;
Cout <(str5 = str6) <endl;
Cout <(str7 = str8) <endl;
Result: 0 0 1 1
Answer: str1, str2, str3, and str4 are array variables with their own memory space. str5, str6, str7, and str8 are pointers pointing to the same constant area. Note that the C language is not like this. The constant address is also different.
4. pointer reference ......
Main ()
{
Int a [5] = {1, 2, 3, 4, 5 };
Int * ptr = (int *) (& a + 1 );
Printf ("% d, % d", * (a + 1), * (ptr-1 ));
}
Output: 2, 5
& A is an array pointer, whose type is int (*) [5]; while adding a pointer to 1 should add a certain value according to the pointer type, different types of pointers + 1 increase with different sizes. A is an int array pointer with a length of 5. Therefore, you must add 5 * sizeof (int ). Therefore, ptr is actually a [5]. But the prt and (& a + 1) types are different (this is important), so the prt-1 will only subtract sizeof (int *). A, & a has the same address but different meanings. a is the first address of the array, that is, the address of a [0], and a is the first address of the object (array, a + 1 is the address of the next element of the array, that is, a [1]. & a + 1 is the address of the next object, that is, a [5].
5. Four Conditions for deadlock
Mutual Exclusion, request persistence, non-deprivation, loop
6. deadlock handling
Ostrich policy, prevention policy, avoidance policy, detection and deadlock Removal
7. What are the Process Scheduling Policies in the operating system?
FCFS (service first), priority, time slice rotation, multi-level feedback
8. What layer does tcp/udp belong? What are the advantages and disadvantages of tcp/udp?
Tcp/udp belongs to the transport layer
The TCP Service provides data stream transmission, reliability, effective traffic control, full duplex operations, and Multiplexing technologies. Unlike TCP, UDP does not provide reliable IP protocol mechanisms, stream control, and error recovery functions. Because UDP is relatively simple, the UDP header contains a few bytes, which consumes less than the TCP load.
Tcp: provides stable transmission services with traffic control. The disadvantage is that the packet header is large and the redundancy is poor.
Udp: it does not provide stable services, with a small packet header and low overhead.
9. Are the results of (void *) ptr and (* (void **) ptr the same? Ptr is the same pointer.
Is the same.
The first option is to forcibly convert ptr to a pointer of the null type. The second (* (void **) ptr first looks at it and converts it to the void pointer, that is, the second-level pointer. Add * to the front to get the content, so the content is also a pointer. This pointer points to a null type. Therefore, after forced conversion, the pointer is the same as the first one.
10. How do I assign a value to the absolute address 0x100000? What should I do if I want to redirect the program to an absolute address 0x100000 for execution?
(Unsigned int *) 0x100000 = 1234
First, convert 0x100000 to a function pointer, that is, (void (*) () 0x100000. Then call it:
* (Void (*) () 0x100000 )();
Typedef is more intuitive: typedef void (*) () voidFuncPtr; * (voidFuncPtr) 0x100000 )();
This blog is from Asura.