C language---basic statements (interview questions)

Basic Statements in C Language and Frequently Asked Interview Questions

1. switch statement

Note : Only integer types (including character types) and enumeration types are in parentheses

Interview question : What is the difference between switch-case and if-else?

①When the case statement is less than 3 sentences, it is the same as the underlying implementation of if-else**; ②Linear
search
When the case statement is greater than 4 , and the sum of the intervals between two adjacent cases does not exceed 6, according to the linear structure search;
③ tree search
When the difference between the largest case and the smallest case is greater than 255 , the compiler will perform tree search . Arrange the data from small to large, take the middle value (if it is an even number, take the one to the right of the middle value), and continue to take the middle value to divide the left and right sides until it is less than or equal to 3 data.

2. The goto statement can only jump within the function body

3. Interview questions: What is the difference between break and continue?

break is to jump out of the current loop , end the entire loop process , and no longer judge whether the conditions for executing the loop are established.
continue is to end the current loop , rather than terminating the execution of the entire loop .

Note : In a loop statement, the break statement and the continue statement are generally used together with the if statement. break and continue cannot be used in any other statement except loops and switch statements.

4. Interview question: In an infinite loop, which is more efficient, while(1) or for(;;)?

for(;;) is more efficient , with two ;; empty statements, the compiler will generally get rid of it and enter an infinite loop directly. And while(1) needs to judge whether the constant 1 is equal to 0 each time it loops .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325702345&siteId=291194637