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 6 of 7.

Keerthi said:   1 decade ago
How to rewrite the program without error? I can't understand from above explanation? any one can do this?

Sonu said:   1 decade ago
Lvalue means adressable value where rvalue means actual value ie location and read value respectively.

Thiyagu said:   1 decade ago
Nice explanation from sam.

Purushotham said:   1 decade ago
All of you know array name itself act as a pointer. Here this base pointer act as a constant pointer. Constant pointer means it will not allowed to change address. So it gives an error.

Sam said:   1 decade ago
Here to do the computation left hand value of array are required, but here a is treated as simple variable in for loop not as array that why error is coming.

Sugan said:   1 decade ago
What is lvalue and rvalue?

Sachin said:   1 decade ago
This is the nice one.

Chai said:   1 decade ago
@Apu: Lvalue and Rvalue means left hand side and right hand side respectively, required while doing the assignment operation.

Apurva Nigam said:   1 decade ago
Can anybody please explain what are Lvalue, Rvalue required errors?

Mukul garg said:   1 decade ago
The only thing which provide functionality of random access is contiguous memory allocation and array has only its base address to access all elements of the array if we modify this then array can not be able to know the starting address so this gives error.


Post your comments here:

Your comments will be displayed after verification.