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 5 of 7.
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?
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.
Purushotham said:
1 decade ago
All of you know array name itself act as a pointer. Here this base pointer act as a constant pointer. Constant pointer means it will not allowed to change address. So it gives an error.
Thiyagu said:
1 decade ago
Nice explanation from sam.
Sonu said:
1 decade ago
Lvalue means adressable value where rvalue means actual value ie location and read value respectively.
Keerthi said:
1 decade ago
How to rewrite the program without error? I can't understand from above explanation? any one can do this?
Prakash said:
1 decade ago
int main()
{
int a[] = {10, 20, 30, 40, 50};
int j;
for(j=0; j<5; j++)
{
printf("%d\n", a[j]);
}
return 0;
}
compile this you all can note down the difference ..Thank You
{
int a[] = {10, 20, 30, 40, 50};
int j;
for(j=0; j<5; j++)
{
printf("%d\n", a[j]);
}
return 0;
}
compile this you all can note down the difference ..Thank You
Satish said:
2 decades ago
Hey this is difficult one. I can explain this after seeing in the text book
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers