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 7 of 7.
Veeraselvi said:
1 decade ago
What you mean by Lvalue & Rvalue?
Praveen said:
1 decade ago
Array name itself act as a pointer and it is a constant pointer. So it can not be modified even if you apply a Lvalue to it still it would give you the same error. So you can't modify constant pointer.
You can write this way
printf("%d",(a+1)); inside for loop. It will print the addresses if you want values to be printed then write *(a+1) instead of (a+1).
You can write this way
printf("%d",(a+1)); inside for loop. It will print the addresses if you want values to be printed then write *(a+1) instead of (a+1).
Kunal Bansal said:
1 decade ago
It's simple , thing is you can do arithmetic operation like ++,-- and others on pointers but these operation are not allowed while implementing on array .
Reason : pointer is a variable
array name is not a variable
Reason : pointer is a variable
array name is not a variable
Prashant singh said:
1 decade ago
Array name itself act as a pointer and it is a constant pointer. So it can not be modified even if you apply a Lvalue to it still it would give you the same error. So you can't modify constant pointer.
Simply a constant pointer can not be modified.
Simply a constant pointer can not be modified.
Sudha said:
1 decade ago
@Sugan.
An "lvalue" of a variable is the value of its address, i.e. where it is stored in memory.
The "rvalue" of a variable is the value stored in that variable (at that address).
An "lvalue" of a variable is the value of its address, i.e. where it is stored in memory.
The "rvalue" of a variable is the value stored in that variable (at that address).
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers