Hangzhou Tian Li Pen question

Source: Internet
Author: User

the role of the 1.volatile keyword, for example three applications.

Generally,volatile is used in several places:

1, the change in the Interrupt service program for other programs to detect variables need to add volatile;

2, multi-tasking environment to share the logo should be added volatile;

3, Memory mapping hardware register usually also add volatile description, because each time it read and write may have different meanings;

2. define a function that returns values and arguments are function pointers

typedef void (*P) (void)

P func (P p1);

Or:void (*) (void) func (void (*) (void))

void (*func (void (*p) (void)) (void);

3. in-memory size end mode?

Big-endian mode, refers to the high byte of data is kept in the low address of memory, and the low byte of data is kept in high memory address, such storage mode is a bit similar to the data as a string order Processing: The address from small to large increase, and data from high to low;

Small-end mode, refers to the high-byte data stored in the high address of memory, and the low byte of data is kept in the low memory address, this storage mode of the high and low value of the address and data to effectively combine the higher address part of the high weight, lower address part of the low weight, and our logical method consistent.

4. What kinds of sorting algorithms are there? bubble sort with C

void sort (int arr[],int size) {

1. the number of rounds that the outer loop controls compare

2. Inner Loop controls the subscript range for each round comparison

int i=0,j=0;

for (i=0;i<size-1;i++) {

for (j=0;j<size-i-1;j++) {

if (Arr[j]>arr[j+1]) {

int TEMP=ARR[J];

ARR[J]=ARR[J+1];

Arr[j+1]=temp;

}

}

}

}

Common sorting algorithms

2.1 Bubble Sort

Comparison of elements between adjacent locations

(1) algorithm flow

A. comparing elements of adjacent positions if the left is larger than the right, then the position of the two elements is exchanged

B. repeat the previous step for each element of the adjacent position, from the first pair to the last pair .

After this step, the final element is the maximum of this set of numbers

C. repeat the above steps for all elements, comparing the fewer and smaller elements each time until there is no

The elements that can be swapped

(2) algorithm evaluation

Average time complexity O (n^2), stable, sensitive to the ordering of samples

2.2 Insert Sort

(1) process of the algorithm

A. from the first element, assume that the element is ordered

B. From the second element, compare it to the already ordered element from the back forward

C. if the left element is greater than the removed element, the left element is assigned to the next position

Continue to compare with ordered elements

D. if the element on the left is less than the removed element, the removed element is inserted after the left element

E. repeat the above steps until all elements have been processed

(2) algorithm evaluation

Average time complexity O (n^2), stable, sensitive to the ordering of samples, but the number of assignments

Less than bubble sort, so slightly better than bubble sort

2.3 selection Sorting algorithm

(1) process of the algorithm

A. remove all elements sequentially from the first number, assuming that the element being removed is the minimum value and the subscript is recorded

B. use the assumed minimum and subsequent elements to compare sequentially, if there is a ratio in the subsequent elements

Assuming that the smallest element is also small, the subscript is re-recorded, and subsequent elements are assumed to be the minimum number

C. until the assumed minimum element and all subsequent elements are compared, the most recent minimum element and

The smallest element to start assuming

D. repeat the process until all elements have been sorted

(2) algorithm evaluation

Average time complexity O (n^2), unstable, insensitive to the order of the samples, compared more often

Less than the number of exchanges, generally slightly better than bubble sort

2.4 Quick Sort

(1) process of the algorithm

A. Select an intermediate element as the base value and store it separately

B. use the left element and the right element and the Datum value comparison respectively to place the element that is smaller than the base value on the left

Place elements that are larger or equal than the base value on the right,

C. repeat the process until the subscript of both sides of the element is coincident so that the datum value is placed in the coincident position, at which point

Elements that are smaller than the base value are already to the left of the datum value, and elements larger than the Datum value are already on the right side of the Datum

D. recursively sort the elements to the left and right of the datum values in a recursive manner

(2) algorithm evaluation

The average time complexity O (nlogn) is unstable, and if each allocation can be evenly divided, this sort of situation is the fastest

5.ISR Interrupt Service subroutine error :

ISR cannot have a return value;

ISR cannot pass parameters;

The ISR should be short and efficient, and It is unwise to do floating-point operations in the ISR;

there should be no re-entry and performance problems in the ISR, so the printf () function should not be used .

__interrupt Double Compute_area (double radius)

{

Double area = PI * radius * RADIUS;

printf ("\narea =%f", area);

return area;

}

1) The ISR cannot return a value. If you do not understand this, then you will not be employed.

2) The ISR cannot pass parameters. If you do not see this, your chances of being employed are equal to the first item.

3) in many processors / compilers, floating-point is generally non-reentrant. Some processors / compilers require additional registers to be stacked, and some processors / compilers do not allow floating-point operations in the ISR .

In addition, theISR should be short and efficient, and It is unwise to do floating-point operations in the ISR.

4) with the 3rd same strain,printf often has re-entry and performance problems. If you lose the third and 4th, I will not be too difficult for you. Needless to say, if you can get the post two o'clock, then your employment prospects are getting brighter.

6.while (1), for (;;), goto dead loop with Which? Why

General for (;;) Superior Performance

for (;;)

{}

these two ;; empty statements, the compiler will generally be better off, directly into the dead loop

while (1)

{}

Each cycle is judged by whether the constant 1 is equal to zero, where the while is more than for the

But from a compilation standpoint, it's the same code.

The goto statement is usually not used, mainly because it will make the program level unclear, and difficult to read, but in the multi-layered nesting exit, with a goto statement is more reasonable.

7. preemptive kernel and non-preemptive kernel?

Kernel preemption (preemptive kernel):

That is, when a higher-priority task occurs when a process is in kernel space, you can suspend the current task and execute a higher-priority process if the current kernel allows preemption.

Non-preemptive kernel:

A high-priority process cannot preempt a low-priority process running in the kernel while it is running on the CPU . Once a process is in a nuclear mindset ( such as a user process executing a system call ), the process will continue to run unless theprocess voluntarily abandons the CPU. Until the kernel is completed or exited.

The meaning of the preemptive kernel:

First, this is the linux 100ms class. This is unacceptable for systems that require a high real-time response. The preempted kernel is not only for linux The real-time application of linux (Video, audio)

Hangzhou Tian Li pen question

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.