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;
}
Discussion:
65 comments Page 4 of 7.
Mohanraj r said:
8 years ago
Explain it please.
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.
Shweta said:
7 years ago
Array is a constant pointer so we can't increment or decrement an array.
Kiran said:
1 decade ago
Can any one explain what exactly lvalue and rvalue means ?im not getting them?
Suresh said:
1 decade ago
Where is l here, wat is that?
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
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).
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.
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.
Apurva Nigam said:
1 decade ago
Can anybody please explain what are Lvalue, Rvalue required errors?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers