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 1 of 7.
Satish said:
2 decades ago
Hey this is difficult one. I can explain this after seeing in the text book
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?
Chai said:
1 decade ago
@Apu: Lvalue and Rvalue means left hand side and right hand side respectively, required while doing the assignment operation.
Sachin said:
1 decade ago
This is the nice one.
Sugan said:
1 decade ago
What is lvalue and rvalue?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers