**Table of contents**

🏀1. Explanation of three custom types of homework

🏀3. File opening and closing operations

🏀4. Preprocessing and Compilation

# 🏀 1. Explanation of three custom types of homework

Blurred knowledge? Go and make it up yourself, “Three Custom Types of Portals”

### 🥅 Exercise 1:

❤️ For size A⭐️Find the alignment numbers first, which are 4, 2, 1, 4; starting from 0, 0-3 is a; 4-5 is b; 6 and 7 are not multiples of 4 to skip, 8-11 is c; 12 is d; so the final result is that 0-12 occupies 13 bytes, but not a multiple of 4, so the final result is: 16

❤️ For size B⭐️First find the alignment numbers, which are 4, 2, 4, and 1; starting from 0, 0-3 is a; 4-5 is b; 6 is c; 7 is not a multiple of 4 to skip, and 8-11 is d; So the final result is that 0-11 occupies 12 bytes, which is a multiple of 4, so the final result is: 12

### 🥅 Exercise 2:

❤️ For the size of stT1⭐️It occupies 0-11,12 bytes in total, which is a multiple of 4, and the final result is: 12

❤️ For the size of stT2⭐️It occupies 0-11,12 bytes in total, which is a multiple of 4, and the final result is: 12

❤️ For stT3 size⭐️A total of 0-15,16 bytes, which is a multiple of 4, the final result is: 16

### 🥅 Exercise 3:

❤️Here are mainly two knowledge points: bit segment and macro⭐️ For the bit segment, it is all char type, so when creating it, it is created one byte by one byte (8 bits), and then it starts to create a byte with 8 bits, and 4 are used for the first time. There are 4 bits left; 2 bits are used for the second time, and 2 bits are left; the third time a byte is used, the remaining 2 bits are not enough to be discarded, and a byte is recreated; the fourth time is recreated A byte, but only 1 bit is used; so it ends up taking up 3 bytes.

⭐️The final result is: 3*2+3=9

### 🥅 Exercise 4:

❤️ The test is the storage form of the bit segment⭐️ In VS, members in a bit segment are allocated in memory from right to left (from low address to high address)!

⭐️In VS, the extra bits are not enough, they are directly discarded, and new ones are used directly after opening up new space!

⭐️Print in hexadecimal form:

### 🥅 Exercise 5:

❤️The test is the storage form of the consortium⭐️ The size of the union variable, at least the size of the largest member; is it 14? But 14 is not a multiple of the maximum alignment of 4, so the final result is: 16

### 🥅 Exercise 6:

❤️The test is about the storage form of the consortium and the problem of the lower end⭐️Occupies the same piece of memory, and they all occupy 2 bytes; the first byte is hexadecimal 39; the second byte is hexadecimal 38; as the subscript grows, the address is from low to low To high, so the left 39 is the low address, the right 38 is the high address; the low address is placed on the right, and the high address is placed on the leftmost.

### 🥅 Exercise 7:

❤️The test is enumeration⭐️No assignment starts from 0 by default, so enumA = Y1 is 1; B1 is the number after 255, so enumB = B1 is 257

# 🏀 2. Dynamic Storage

Blurred knowledge? Make it up yourself, “Dynamic Storage and Soft Arrays”

### 🥅 Exercise 1: (difficulty)

❤️ use of atoi⭐️ Convert a string to an integer

**❤️Atoi’s simulation implementation (first look at an article to clarify the idea)**

# 🏀 3. File opening and closing operations

Blurred knowledge? Go and make it up yourself, “File Operation”

❤️getchar only works on standard input stream (keyboard); not on all streams

### 🥅 Exercise 1:

**❤️Interpretation of the program, examine the understanding of several commonly used file operation functions**

### 🥅 Exercise 2:

❤️

sscanfis to read formatted data from strings; sprintf is to write formatted data to [strings] This intermediate file is compiled to generate object code; three steps: pre-compilation (preprocessing), compilation

,assembly Is the called function defined

❤️Whichof the following is not a pointer?

`</p> <h1>define INT_PTR int* //equivalent to replacing</h1> <p>typedef int * int_ptr; //define aliases INT_PTR a, b; //int<em> a,b;====>a is a pointer, the type is int; b is not a pointer, the type is int int_ptr c, d; //The types of c and d are all int</em> pointer types`

❤️ Thefeof function is not used to judge whether the file is read or not; it is to judge the reason for the end of the file after the end of the file

❤️When reading the text to judge whether it is over, fgetc checks whether the return value is EOF; fgets checks whether the return value is NULL

❤️BinaryThe file judges that the reading is over and sees whether the actual number of readings is less than the required number of readings

# 🏀 4. Preprocessing and Compilation

Blurred knowledge? Make it up yourself, “Preprocessing and Compilation”

### 🥅 Exercise 1:

**❤️Inspecting the understanding of macros, we must first bring them in as a whole, instead of calculating them.**

### 🥅 Exercise 2:

**❤️Be sure to pay attention to the use of parentheses when defining macros**

### 🥅 Exercise 3: (emphasis)

❤️Write a macro to swap the odd and even bits of an integer binary for⭐️Essence : In

fact, even-numbered bits are shifted right by 1; odd-numbered bits are shifted left by 1 bit⭐️Ideas : Take out the odd bits of the data, and then shift one bit to the left; take out the even bits of the data, and then shift one bit to the right; finally add it up

!How to get the odd and even digits?⭐️

For example:

**❤️Specific macro implementation**

### 🥅 Exercise 4: (emphasis)

**❤️The use of offsetof**

**❤️offsetof is implemented using the simulation of macros**