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

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.

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)

Coder x said:   8 years ago
You cannot increment and decrement operations on the array directly. You need a pointer to be able to access the values of the pointer.

Kausa chan said:   5 years ago
No, @Kiran.

Because ptr is just pointer to an integer and you're storing the address of an array to it so it will throw an error.
(1)

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

Vallinayagam said:   7 years ago
In an array, it is not possible to perform increment/decrement by using the array name. If we want we can use a pointer.
(1)

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.

Nani said:   6 years ago
We can't do. a=a+1;

Because base address will change. This is illegal. If a is pointer we can do it.
(2)

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

int **p;

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


Post your comments here:

Your comments will be displayed after verification.