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

Tim said:   1 decade ago
The a++ generates "non l-value in assignment" in GNU G++ and "wrong type argument to increment" in GNU C compiler. Your test should be about the C LANGUAGE, not about specific error messages in the C# compiler.

Deepak said:   1 decade ago
Ya. What Ashwini said was right. I want to add some more things to it. It does not allow us to directly over write the base pointer. So if we want to change it, We need to copy it to another pointer and then perform increment or decrement. Tht is what the error it is giving 'L value required' (Left side value).

Aswini said:   1 decade ago
The reference to the variable a refers to the base address of array a[].In general the statement a++ increments and assigns the value back to a.But here this statement affects the base address of an array while incrementing and assigning it to a......this what i understood

Suresh said:   1 decade ago
Where is l here, wat is that?

Satish said:   2 decades ago
Hey this is difficult one. I can explain this after seeing in the text book


Post your comments here:

Your comments will be displayed after verification.