#include "stdio.h" main() { char a[4][5]={"ABCD","EFGH","IJKL","MNOP"}; char (*p)[5]; int i,j; p=a; for(i=0;i<4;i++) { for(j=0;j<4;j++) printf("%c",*(*(p+i)+j)); /* 第 9 行 */ printf("\n"); } }
时间: 2023-11-22 11:53:11 浏览: 78
这段代码有些问题,正确的写法应该是:
```c
#include <stdio.h>
int main() {
char a[4][5] = {"ABCD", "EFGH", "IJKL", "MNOP"};
char (*p)[5];
int i, j;
p = a;
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++)
printf("%c", *(*(p + i) + j));
printf("\n");
}
return 0;
}
```
这段代码的输出结果是:
```
ABCD
EFGH
IJKL
MNOP
```
这是一个二维字符数组的例子,每个元素都是一个长度为 5 的字符串。p 是一个指向长度为 5 的字符数组的指针,即 `char (*)[5]` 类型。在第 9 行中,`*(*(p+i)+j)` 表示取出 p+i 这一行中的第 j 个字符。
相关问题
#include<stdio.h>和 #include "stdio.h" 有啥区别
在C语言中,#include是一个预处理指令,用于在编译程序之前将指定的头文件包含到源代码中。其中,#include <stdio.h>和#include "stdio.h"都是用来包含头文件<stdio.h>的指令。但它们有以下几点区别:
1. #include <stdio.h>是从系统目录中查找头文件,而#include "stdio.h"是从当前目录中查找头文件。
2. 如果在当前目录和系统目录中都存在同名的头文件,则#include "stdio.h"会优先使用当前目录中的头文件,而#include <stdio.h>则会使用系统目录中的头文件。
3. 如果使用了编译器的特殊选项,如-I选项,指定了头文件的搜索路径,则#include <stdio.h>会在指定的路径中查找头文件,而#include "stdio.h"仍然会在当前目录中查找头文件。
综上所述,#include <stdio.h>和#include "stdio.h"的主要区别在于它们查找头文件的方式不同。如果你需要包含C标准库的头文件,则通常使用#include <stdio.h>;如果你需要包含自己编写的头文件,则通常使用#include "stdio.h"。
#include <stdio.h> #include <string.h> char str[]="abcde"; int main() { printf(str[3]); return 0; }
这段代码有一个错误,printf函数的第一个参数应该是一个字符串,而不是一个字符。如果想打印字符串中的某个字符,应该使用以下代码:
```
#include <stdio.h>
#include <string.h>
char str[]="abcde";
int main() {
printf("%c", str[3]);
return 0;
}
```
这样就可以正常打印字符串中的第4个字符 'd' 了。
相关推荐
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)