Why this error occurs?
Expression ptr[0] has type char[1] because ptr is declared lika pointer to array of type char[1]
char (*ptr)[1];
Expression cad has type char * and is equal to the address of the first character of array cad.
From the C Standard (6.3.2.1 Lvalues, arrays, and function designators)
3 Except when it is the operand of the sizeof operator or the unary &
operator, or is a string literal used to initialize an array, an
expression that has type ‘‘array of type’’ is converted to an
expression with type ‘‘pointer to type’’ that points to the initial
element of the array object and is not an lvalue. If the array object
has register storage class, the behavior is undefined.
Thus in the left side of the assignment statement
ptr[0] = cad;
there is an array of type char[1]. In the right side of the assignment there is a pointer of type char *. These types are incompatible and arrays do not have the assignment operator.
It seems you mean the following
#include <stdio.h>
int main(void)
{
char cad[] = "abc";
char * ptr[1];
ptr[0] = cad;
// puts( ptr[0] );
return 0;
}
ptr[0]is an array (because you told it so). Therefore,ptr[0]cannot be on the left side of an assignment operator.