#include<stdio.h>
#include<conio.h>
void main()
 {
  int a[] = {10,20,30,40,50},j,*p;
  clrscr();
   for(j=0;j<5;j++)
    {
     printf("%d",*a);
     a++;/*here compiler error  "lvalue required"*/
    }
   p=a;
   for(j=0;j<5;j++)
    {
     printf("%d",*p);
     p++;
    }
  getch();
 }

i used turbo c++ compiler.and save this programme as abc.c
why this type of errors occur?

Recommended Answers

All 7 Replies

a isn't an integer, it's an array of integers.

More explicitly, even though int a[5]; and int *a; both declare a to be a pointer to an integer, the first is constant, meaning that you cannot change the value of a (it cannot be used as an lvalue).

You will save yourself some accidental grief if you keep different types of variables in different declarations. (It doesn't save that much space to combine them all together.)

int a[] = {10,20,30,40,50};  /* an array of int */
  int j;                       /* an int */
  int *p;                      /* a pointer to int */

Hope this helps.

a is an array. but ur using it as a pointer. if you want use like this so place an * before a[]. then the problem is solved.

commented: Go away spammer -1

a is a array only. change it as pointer array.

commented: Go away spammer -1

a is an array so a++ means you are incrementing the value (index value).

commented: Go away spammer -1

put *a++;
and remove rest :P

Thread closed thanx to spammers JamesMatthew, MatthewGrace and GraceTaylor which are posting same rubbish

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.