I'm trying to print an int array, but it gives me an error.
error: lvalue required as increment operand
int *a[] = {1,2,3,4,5};
for(int i=0;i<5;i++)
{
printf("%d",*a);
a++;
}
int *a[]
means an array of pointers to ints. You want an array of ints here, so use int a[]
.
You can't increment a
because a
is an array, not a pointer. Arrays sometimes decay to pointers to the first element, but you can't modify that pointer. Instead, make a pointer pointing to the elements in the array like int *p = a
or use the subscript operator like a[i]
to access the elements.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments