C Programming - Pointers - Discussion

Discussion Forum : Pointers - Point Out Errors (Q.No. 2)
2.
Point out the error in the program
#include<stdio.h>

int main()
{
    int a[] = {10, 20, 30, 40, 50};
    int j;
    for(j=0; j<5; j++)
    {
        printf("%d\n", a);
        a++;
    }
    return 0;
}
Error: Declaration syntax
Error: Expression syntax
Error: LValue required
Error: Rvalue required
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
65 comments Page 2 of 7.

Coder x said:   8 years ago
"Lvalue required" means you cannot assign a value to something that has no place in memory. Basically you need a variable to be able to assign a value.
(1)

Mohanraj r said:   8 years ago
Explain it please.

Amrendra said:   8 years ago
The lvalue is an object that has identifiable memory location.

For example:
int i=9 ;
here i is a lvalue because it has identifiable memory location and possible to modify its content.
int *p=&i (identifiable memory location),
*p=4;

rvalue : any object that is not lvalue.

For exapmle: int i =2; here 2 is a rvalue because int *p= &2 //error,
int x=y+5; y+5 is a rvalue because int *p= &(y+5) //error.

Sriram said:   9 years ago
Well explained @Shri.

Deepak said:   9 years ago
LValue means Left value.

Spoorti said:   9 years ago
@Shri.

Good explanation. I got it clearly.

Sunil said:   9 years ago
Trying to increment or decrement constant expression then Lvalue required error occurs.

Maniikanta said:   9 years ago
Can I declare a pointer like,

int **p;

Is this is correct or wrong? Please explain the reason.

Vinay Rao said:   9 years ago
Array name a holds the base address of the array. You cannot change it.

In the above program,
a++ means a= a+1.
But a holds base address...It's not a variable.

So, if base address is 1000, it becomes;
1000 = 1000+1;

This does not mean anything. Because Lvalue(i.e., Left side reference) is missing.

Jagan said:   10 years ago
A is constant pointer it is not possible to increment.


Post your comments here:

Your comments will be displayed after verification.