0
#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?

8
Contributors
7
Replies
10
Views
9 Years
Discussion Span
Last Post by peter_budo
0

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.

-4

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.

Votes + Comments
Go away spammer
1

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.