B
Bigdakine
Subject: doubt in USING POINTERS
You can't increment x, which is a pointer to an array position like that,
hence you get the message unmodifiable L-value. Good thing too. All sorts of
trouble could result. Instead after defining x, add the statement
int ptr2xelem* = (int *) NULL;
And then set
ptr2xelem=&x[0];
And then you can write things like ptr2x++;
If you want to keep track of an index or something like that.
Stuart
From: (e-mail address removed) (ambika)
Date: 9/21/03 4:28 AM Hawaiian Standard Time
Message-id: <[email protected]>
Hello,
Am not very good with pointers in C,but I have a small doubt about
the way these pointers work..
We all know that in an array say x[5],x is gonna point to the first
element in that array(i.e)it will have the address of the first
element.In the the program below am not able to increment the value
stored in x,which is the address of the first element.Why am I not
able to do that?Afterall 1 is also a hexadecimal number then why
does adding 1 to x show me a error?
I got the message "Lvalue Required" when I complied the program.Even
if I declared x[5] as long int the same error continued.Can
someone please help me solve it out??
Thanks to all those who are gonna help me in this..
--ambika
#include<stdio.h>
void main()
{
int x[5]={1,2,3,4,5};
printf("\naddr in x:%p",x);
printf("\nnumber in the addr stored in x is:%d",*x);
x=x+1;
You can't increment x, which is a pointer to an array position like that,
hence you get the message unmodifiable L-value. Good thing too. All sorts of
trouble could result. Instead after defining x, add the statement
int ptr2xelem* = (int *) NULL;
And then set
ptr2xelem=&x[0];
And then you can write things like ptr2x++;
If you want to keep track of an index or something like that.
printf("\naddr in x after incrementation is:%p",x);
printf("\nnumber in the addr stored in x is:%d",*x);
}
Stuart