Incompatible pointer to integer conversion initializing 'char' with an expression of type 'char[20]'
时间: 2024-06-01 20:10:30 浏览: 14
This error occurs when you try to initialize a variable of type 'char' with an expression of type 'char[20]'.
For example:
char str[20] = "Hello World";
char c = str;
In this code, the variable 'c' is of type 'char', but we are trying to initialize it with the array 'str', which is of type 'char[20]'. This is not allowed in C/C++, hence the error message.
To fix this error, you need to either change the type of the variable 'c' to 'char[20]', or assign a single character from the array 'str' to 'c' using its index.
For example:
char str[20] = "Hello World";
char c = str[0]; // assign the first character of the array to 'c'
Or:
char str[20] = "Hello World";
char c[20];
strcpy(c, str); // copy the contents of 'str' to 'c'