0
int main()
{
    int[] x={1,2,3,4,5};
    printf("%d",x);
    printf("%d",*x);
    printf("%d",++*x);
    printf("%d",*x++);   //Here Lvalue required erroe  is genrerated
}

Can someone please explain me what is meaning of this error and why it is generating here

Raging Bull
  • 18,593
  • 13
  • 50
  • 55
user3335653
  • 133
  • 1
  • 8
  • 3
    Other errors aside, you're trying to increment an array. That makes no sense. – chris Feb 22 '14 at 06:28
  • 3
    Congratulations. You now have your own official "this is why arrays and pointers are *not* the same* code sample to throw in the face of those that claim they are. Not that it matters, since your syntax is wrong anyway. `int[] x` should be `int x[]`. Might wanna fix that before winding up the pitching arm. – WhozCraig Feb 22 '14 at 06:42
  • I am a java programmer.i Used to programm in c just few days ago.Si that i why fingers are still java oriented.Sorry for my mistake. – user3335653 Feb 22 '14 at 08:25

5 Answers5

0

The correct way to declare array in c/c++ is :

int x[]={1,2,3,4,5};

The error is because you can not use ++ on array

uchar
  • 2,552
  • 4
  • 29
  • 50
0

You can't increment an array.

*x++ is the same as *(x++). Maybe you wanted (*x)++ instead?

user253751
  • 57,427
  • 7
  • 48
  • 90
0

In this statement:

printf("%d",*x++); 

You are applying the ++ operator to the array itself, which is not possible. This gives you the lValue error.

Alternatively, in this one:

printf("%d",++*x);

You are applying the ++ operator to the value pointed to by the array (its first element), which of course works fine and just prints the value of next element.

Try

printf("%d",(*x)++); 
Amarnath Balasubramanian
  • 9,300
  • 8
  • 34
  • 62
RahulKT
  • 171
  • 4
  • its ok the increment in array makes no sense.But array is just a pointer variable. I mean if I print the value of x in my program(which is an array) it will print address of a[0].It mean it is pointer to a[0].So when I can use increment on a simple pointer variable then why I can not use increment operation on array pointer. – user3335653 Feb 22 '14 at 06:57
  • yes true Agree with you – RahulKT Feb 22 '14 at 06:58
0

You can't increment an array. Try this:

int main()
{
    int x[]={1,2,3,4,5};
    printf("%d",x);
    printf("%d",*x);
    printf("%d",++*x);
    int *y=x;
    printf("%d",*y++); //you can increment a pointer though
}
HelloWorld123456789
  • 5,299
  • 3
  • 23
  • 33
-1

its ok the increment in array makes no sense.But array is just a pointer variable. I mean if I print the value of x in my program(which is an array) it will print address of a[0].It mean it is pointer to a[0].So when I can use increment on a simple pointer variable then why I can not use increment operation on array pointer.

user3335653
  • 133
  • 1
  • 8