Lvalue required as an error pointer for an increment pointer

I'm just trying to understand the concept of pointers in C and stumbled upon this error. I got the error "lvalue required as increment operand" for the following code. Please help me understand what is wrong.

#include<stdio.h>

int main()
{
    char *s[] = {"black", "white", "pink", "violet"};
    ++s; //error at this line
    printf("%s\n", *s);
    char **ptr[] = {s+3, s+2, s+1, s}, ***p;
    p = ptr;
    ++p;
    printf("%s", **p+1);
    return 0;
}
+4
source share
2 answers

s- an array of pointers to char. Array names do not change l-value. ++schanges sthat cannot be changed.

Array names versus pointer variables :

, , , ( ) , . . , , . , . , , C, , Lvalue. , , Lvalues.


: C?

+1

, rvalue . char **. . ,

int x = 10;

++( x + 5 );

.

,

char **ptr[] = { ++(s+3), s+2, s+1, s};

. , ++s, ++( s + 0 ), , , rvalue`

+1

Source: https://habr.com/ru/post/1546033/


All Articles