Solutions for Xiyou Linux Group 2022 Interview Questions
Solutions for Xiyou Linux Group 2022 Interview Questions
Thanks to Zhilu for re-entering the original title. Good people live in peace.
- This topic is only a limited reference for the
Xiyou Linux Group
2022 interview.- In order to save layout, the program source code of this question omits the
#include
directive.- The program source code in this question is only used to examine the basics of the C language, and should not be used as an example of the “code style” of the C language.
- The questions is arranged randomly on difficulty.
All topics are compiled and run onx86_64 GNU/Linux
environment.Message from the seniors:
For a long time, the interview questions of Xiyou Linux Group have been known in XUPT for their high difficulty. We, as test-makers, also know that this test is slightly difficult. Please do not worry. **If you can complete half of the questions, it is already very good. ** Secondly, we are more interested in your thinking and process than the answers to the questions. Maybe your answer is slightly flawed, but your correct thinking and understanding of knowledge are enough to win more points. Finally, the process of doing the test is also a process of learning and growth. We believe the test questions will definitely help you to master the C language more familiarly. Good luck. See you at FZ103!Copyright © Xiyou Linux Group, All Rights Reserved.
This exam is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
0. Is my calculator broken?!
2^10=1024
corresponds to 4 digits in decimal, so how many digits does2^10000
correspond to in decimal?
The answer is stated below:
1 |
|
1. Can printf play like this?
1 |
|
- printf() has a return value, the return value is the length of the printed characters. So the first output is empty and the length is 0;
- The second output is “Xiyou Linux Group - 20”, a total of 22 characters so outputs “22”;
- Hence: “Xiyou Linux Group - 2022”
2. Hellllllllllloooooooo!
- The output of the program is a bit strange, please try to explain the output.
- Please talk about your understanding of
sizeof()
andstrlen()
.
1 |
|
- p has been specified, the size is 15, and p1 is a pointer, and the size of the pointer is generally 8 bytes (4 bytes and 32 bits only support a maximum of 4GB memory, which is obviously to be eliminated). *p2 is’H’, 1 byte in size.
- strlen() calculates the length of the string, obviously they are all 11.
3. Can you change the name of the variable?
Please combine this question and talk about your understanding of the “life cycle” of “global variable” and “local variable” in the C language.
1 |
|
- The answer is stated below:
1 |
|
4. Memory misalignment!
What are the characteristics of
union
andstruct
, do you understand their memory allocation mode?
1 |
|
- Memory alignment mainly follows the following three principles:
- The starting address of a structure variable is divisible by the size of its widest member;
- The offset of each member of the structure relative to the starting address can be divisible by its own size, if not, add bytes after the previous member;
- The overall size of the structure can be divisible by the size of the widest member, if not, add bytes after
- For UNION, it is a union, and the space occupied is the maximum value of the member, which is 20, but 20 is not an integer multiple of 8-byte long, so it will increase to 24
- For data, since it contains a UNION, and the widest one in UNION is 8, so 4+(4) (for divisibility)+24+8 = 40
5. Bitwise
- Please use a pen and some paper to deduce the outputs of this program.
- Please talk about your understanding of bit operations.
1 |
|
- The answer is stated below:
1 |
|
6. English to Chinese
Please talk about the meaning of the following data types, talk about the role of
const
.
char *const p
.char const *p
.const char *p
.
char const *p
andconst char *p
are the same thing, The value pointed by p cannot be changed.char *const p
means that the p always points the same variable, cannot be changed.
7. Chinese to English
Please use the variable
p
to give the following definition:
- An array of 10 pointers to
int
.- A pointer to an array of 10
int
s.- An array of 3 “pointers to functions”, the pointed function has 1
int
parameter and returnsint
.
1 |
|
8. Order in Chaos
How much do you know about sorting algorithms?
Please talk about the idea, stability, time complexity and space complexity of the sorting algorithms you know.
Hint: It’s better to knock it out with your own hands~
- Bubble sorting, similar to bubbling in water, the larger number sinks, and the smaller number slowly rises. Assuming from small to large, that is, the larger number is slowly arranged to the back, and the smaller number is slowly moved to the back. front row.
1 |
|
- Selection sorting: First find the smallest element in the unsorted sequence, store it at the starting position of the sorted sequence, then continue to find the smallest element from the remaining unsorted elements, and then put it in the second element position. And so on until all elements are sorted.
1 |
|
- Bubble sort is to compare the left and right numbers, while selection sort is to compare the latter numbers with the first number in each round;
- Bubble sort has more exchanges per round, while selection sort only exchanges once per round;
- Bubble sort is to find positions by numbers, and selection sort is to find numbers at a given position;
- When an array encounters the same number, bubble sort is relatively stable, while selection sort is unstable;
- In terms of time efficiency, selection sort is better than bubble sort.
9. Hands and Brain
- Please implement the ConvertAndMerge function:
- Concatenate the two input strings, and flip the case of all letters in the new string obtained after concatenation.
- Hint: You need to allocate space for the new string.
1 |
|
10. Give you my pointers, access my inner voice
The output of the program is a bit strange, please try to explain the output of the program.
1 |
|
- This is because temp < arr[5] will be established many times;
- For example, when i == 0, temp points to the 0th address, and arr[5] points to the 25th address. After the loop ends, a == 25
- When i == 1, temp points to the 5th address, and arr[5] points to the 25th address, looping 20 times, overwriting the value after the last loop a[1][*],
- But this time it can only loop 20 times, so after the loop is over, a == 45;
11. Strange parameters
Do you understand argc and argv?
Why is the value of argc 1 when running the program directly?
Will the program be in a loop?
1 |
|
- argc is the number of parameters, here is a signed Integer type. Its value represents the number of parameters entered when executing the program.
- If it is run directly, its value is 1. After entering the loop, its value will overflow, the conditional statement will be executed.
- If your program is a.out, if you run the program on the command line, (First, you should use the cd command to enter the directory where the a.out file is located on the command line)
- The running command is: ./a.out Linux hello
- Then, the value of argc is 3, argv[0] is “a.out”, argv[1] is “Linux”, and argv[2] is “hello”.
12. Strange characters
The output of the program is a bit strange, please try to explain the output of the program.
1 |
|
- The data in the memory is continuously discharged, so after the connection is:
- 636c6557 20656d6f 58206f74 756f7969 6e694c20 00000000 47207875 70756f72 32303220 00000a32
- Because computers generally read in little-endian byte order, the value stored in the computer is:
- 57656c63 6f6d6520 746f2058 69796f75 204c696e 00000000 75782047 726f7570 20323032 320a0000
- 00 is a null character, so it is ignored when being printed, in fact, it prints 57656c63 6f6d6520 746f2058 69796f75 204c696e 320a
- After printing them in order, the result is: Welcome to Xiyou Linux Group 2022/n (0a is a newline)
- The computer circuit processes the low-order byte first, which is more efficient, because the calculation starts from the low-order byte.
- So, the computer’s internal processing is little-endian.
- Inside computers, little endian is widely used to store data inside modern CPUs,
- In other scenarios, such as network transfers and file storage, big endian is used.
13. Small tests on macro definition
- Please talk about your understanding of
#define
.- try to interpret the output of the program.
1 |
|
- The macro definition uses the macro name to represent a string, and when the macro is expanded, the string is used to replace the macro name, which is just a simple and rude replacement.
- A string can contain any character, it can be a constant, an expression, an if statement, a function, etc. The preprocessor does not check it, and if there is an error, it can only be found when compiling the source program that has been expanded by macros.
- The macro definition is not a description or a statement. There is no need to add a semicolon at the end of the line. If a semicolon is added, even the semicolon is replaced together.
Here we go using the rules obove!
1 |
|
14. GNU/Linux commands (Optional)
Do you know the meaning and usage of the following commands:
Note:
Hey! You may not be very familiar with Linux commands, or even you haven’t heard of Linux.
But don’t worry, this is an optional question and won’t have a big impact on your interview!
Knowing about Linux is a plus, but no point is deducted if you don’t!
ls
rm
whoami
- What other GNU/Linux commands do you know?
ls
: list all visible files and foldersrm
: delete a file or folderwhoami
: print the username associated with the current effective user IDlsmod
: used to display modules loaded into the system
- Congrats on getting here! Your perseverance has overcome the vast majority of students who see these test questions.
- Maybe you are not satisfied with your performance, don’t worry, please be confident as before.
- Persistence to get here has proven you are good.
- What are you waiting for, bring your laptop and come to the FZ103 interview!