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

Nila said:   1 decade ago
@Bele.

We use the array's variable name(without subscript )for sake of passing them to a function which receives with a pointer variable.

So now that pointer will be holding the base address of the array..using which you could access the rest of the array elements(coz array elements are continuously stored).

This reduces the degrading of performance like stack overflow in passing arrays on the whole to a function.

Aim said:   1 decade ago
Here printf statement display address of memory location so when we do a++ is increment the address value but here left side any variable is not available to take it. So error is LValue required

Aditya reja said:   1 decade ago
The name of An Array is automatically constant pointer (i.e. cannot be alter) that always points to its 0th element. Due to its constant nature ++ or -- operators can't be apply to array's name.

Balaji said:   1 decade ago
I am not understand explain clearly.

Jana said:   10 years ago
Friends, whether we can assign a pointer to a pointer.

Eg:
{
*b=*a;
}

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

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.

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

int **p;

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

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

Spoorti said:   9 years ago
@Shri.

Good explanation. I got it clearly.


Post your comments here:

Your comments will be displayed after verification.