The value of expression *((int *)(p+1)+2) is __. static struct { int x, y[3]; } a[3] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}}, *p; p = a+1;
时间: 2023-10-06 11:07:25 浏览: 349
The value of expression `*((int *)(p+1)+2)` can be calculated as follows:
1. `p+1` points to the second element of the array `a`.
2. Casting `p+1` to an `int *` pointer type means that the pointer arithmetic will be performed based on the size of `int`, which is typically 4 bytes. So, `p+1` will be incremented by `sizeof(int)` bytes.
3. Adding 2 to the resulting pointer `(int *)(p+1)+2` means that it will be incremented by `2 * sizeof(int)` bytes.
4. Finally, dereferencing the resulting pointer `*((int *)(p+1)+2)` gives us the value of the third integer in the second element of the array `a`, which is `7`.
Therefore, the value of expression `*((int *)(p+1)+2)` is `7`.
相关问题
static int stmmac_rx(struct stmmac_priv *priv, int limit)函数解析
函数名:static int stmmac_rx(struct stmmac_priv *priv, int limit)
函数作用:接收网络数据包
函数参数:
- priv:指向私有数据结构体的指针
- limit:接收网络数据包的数量限制
函数返回值:返回接收网络数据包的数量
函数实现过程:
1. 首先获取 DMA 接收描述符环中的下一个可用描述符;
2. 如果当前接收描述符不可用,则停止接收并返回接收到的数据包数量;
3. 获取接收缓冲区的虚拟地址;
4. 将当前接收描述符的虚拟地址和长度设置到 DMA 控制器中;
5. 等待 DMA 控制器完成数据传输;
6. 分析接收的数据包;
7. 释放接收描述符;
8. 继续接收下一个网络数据包。
函数中的代码实现比较复杂,具体实现可以参考 stmmac_eth.c 文件中该函数的源码。
帮我改写一下这段程序,要求更换为不使用templatetemplate <size_t ARRAY_SIZE> void common_print_border(struct INFORMATION(*information)[ARRAY_SIZE], int L, int C, int cell_width, int cell_height, bool inner_border) { int X = 0, Y = 0; for (int j = 0; j < C; j++) { X = 3 + cell_width / 2 + j * (cell_width + 2 * inner_border); cct_showch(X, 1, information[0][j].C); } for (int i = 0; i < L; i++) { Y = 3 + i * (cell_height + inner_border); if (i == 0) { cct_showstr(2, 2, "╔", COLOR_HWHITE, COLOR_BLACK); for (int j = 0; j < C; j++) { X = 4 + j * (cell_width + 2 * inner_border); cct_showstr(X, 2, "═", COLOR_HWHITE, COLOR_BLACK, cell_width / 2); if (inner_border && j < C - 1) { X += cell_width; cct_showstr(X, 2, "╦", COLOR_HWHITE, COLOR_BLACK); } } X += cell_width; cct_showstr(X, 2, "╗", COLOR_HWHITE, COLOR_BLACK); } for (int j = 0; j <= C; j++) { if (inner_border || j == 0 || j == C) { X = 2 + j * (cell_width + 2 * inner_border); if (!inner_border && j == C) { X += 2; } for (int k = 0; k < cell_height; k++) { if (k == cell_height / 2) { cct_showch(0, Y + k, information[i][0].L); } cct_showstr(X, Y + k, "║", COLOR_HWHITE, COLOR_BLACK); } } } Y += cell_height; if (inner_border && i < L - 1) { cct_showstr(2, Y, "╠", COLOR_HWHITE, COLOR_BLACK); for (int j = 0; j < C; j++) { X = 4 + j * (cell_width + 2 * inner_border); cct_showstr(X, Y, "═", COLOR_HWHITE, COLOR_BLACK, cell_width / 2); X += cell_width; cct_showstr(X, Y, (j < C - 1) ? "╬" : "╣", COLOR_HWHITE, COLOR_BLACK); } } if (i == L - 1) { cct_showstr(2, Y, "╚", COLOR_HWHITE, COLOR_BLACK); for (int j = 0; j < C; j++) { X = 4 + j * (cell_width + 2 * inner_border); cct_showstr(X, Y, "═", COLOR_HWHITE, COLOR_BLACK, cell_width / 2); if (inner_border && j < C - 1) { X += cell_width; cct_showstr(X, Y, "╩", COLOR_HWHITE, COLOR_BLACK); } } X += cell_width; cct_showstr(X, Y, "╝", COLOR_HWHITE, COLOR_BLACK); } } return; }
以下是不使用template的改写程序:
void common_print_border(struct INFORMATION information[][ARRAY_SIZE], int L, int C, int cell_width, int cell_height, bool inner_border) {
int X = 0, Y = 0;
for (int j = 0; j < C; j++) {
X = 3 + cell_width / 2 + j * (cell_width + 2 * inner_border);
cct_showch(X, 1, information[0][j].C);
}
for (int i = 0; i < L; i++) {
Y = 3 + i * (cell_height + inner_border);
if (i == 0) {
cct_showstr(2, 2, "╔", COLOR_HWHITE, COLOR_BLACK);
for (int j = 0; j < C; j++) {
X = 4 + j * (cell_width + 2 * inner_border);
cct_showstr(X, 2, "═", COLOR_HWHITE, COLOR_BLACK, cell_width / 2);
if (inner_border && j < C - 1) {
X += cell_width;
cct_showstr(X, 2, "╦", COLOR_HWHITE, COLOR_BLACK);
}
}
X += cell_width;
cct_showstr(X, 2, "╗", COLOR_HWHITE, COLOR_BLACK);
}
for (int j = 0; j <= C; j++) {
if (inner_border || j == 0 || j == C) {
X = 2 + j * (cell_width + 2 * inner_border);
if (!inner_border && j == C) {
X += 2;
}
for (int k = 0; k < cell_height; k++) {
if (k == cell_height / 2) {
cct_showch(0, Y + k, information[i][0].L);
}
cct_showstr(X, Y + k, "║", COLOR_HWHITE, COLOR_BLACK);
}
}
}
Y += cell_height;
if (inner_border && i < L - 1) {
cct_showstr(2, Y, "╠", COLOR_HWHITE, COLOR_BLACK);
for (int j = 0; j < C; j++) {
X = 4 + j * (cell_width + 2 * inner_border);
cct_showstr(X, Y, "═", COLOR_HWHITE, COLOR_BLACK, cell_width / 2);
X += cell_width;
cct_showstr(X, Y, (j < C - 1) ? "╬" : "╣", COLOR_HWHITE, COLOR_BLACK);
}
}
if (i == L - 1) {
cct_showstr(2, Y, "╚", COLOR_HWHITE, COLOR_BLACK);
for (int j = 0; j < C; j++) {
X = 4 + j * (cell_width + 2 * inner_border);
cct_showstr(X, Y, "═", COLOR_HWHITE, COLOR_BLACK, cell_width / 2);
if (inner_border && j < C - 1) {
X += cell_width;
cct_showstr(X, Y, "╩", COLOR_HWHITE, COLOR_BLACK);
}
}
X += cell_width;
cct_showstr(X, Y, "╝", COLOR_HWHITE, COLOR_BLACK);
}
}
return;
}