我正在尝试学习 C。我目前正在使用指针,所以我决定编写一些代码来看看它是如何工作的。然而,代码按预期工作(即,它在数组中添加字符 aj 并将其打印在控制台上),但我收到有关不兼容的指针分配的警告。我已将警告添加为警告所在行的注释。
#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char * argv[]) {
#define MAX 10
char* c[MAX]; // pointer to the 1st element in the array
char* pointer = &c; // Warning: Incompatible pointer types initializing 'char *' with an expression of type 'char *(*)[10]'
for (int j = 0; j < 10; j++)
{
*pointer = 'a' + j;
pointer++;
}
pointer = &c; // Warning: Incompatible pointer types assigning to 'char *' from 'char …Run Code Online (Sandbox Code Playgroud)