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 6 of 7.
Deepak said:
9 years ago
LValue means Left value.
Sriram said:
9 years ago
Well explained @Shri.
Amrendra said:
8 years ago
The lvalue is an object that has identifiable memory location.
For example:
int i=9 ;
here i is a lvalue because it has identifiable memory location and possible to modify its content.
int *p=&i (identifiable memory location),
*p=4;
rvalue : any object that is not lvalue.
For exapmle: int i =2; here 2 is a rvalue because int *p= &2 //error,
int x=y+5; y+5 is a rvalue because int *p= &(y+5) //error.
For example:
int i=9 ;
here i is a lvalue because it has identifiable memory location and possible to modify its content.
int *p=&i (identifiable memory location),
*p=4;
rvalue : any object that is not lvalue.
For exapmle: int i =2; here 2 is a rvalue because int *p= &2 //error,
int x=y+5; y+5 is a rvalue because int *p= &(y+5) //error.
Mohanraj r said:
8 years ago
Explain it please.
Coder x said:
8 years ago
"Lvalue required" means you cannot assign a value to something that has no place in memory. Basically you need a variable to be able to assign a value.
(1)
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.
Parth said:
8 years ago
The reason why Dennis didn't allowed us to play with the name of the array was b/c it is the only way to access the array we have declared. Ones the base address of the array is lost we can't access it. It still exists in the memory but it's hidden in a pool of 1073741824 bytes of RAM memory.(If you are running on 1GB ).
(2)
Shweta said:
7 years ago
Array is a constant pointer so we can't increment or decrement an array.
Vallinayagam said:
7 years ago
In an array, it is not possible to perform increment/decrement by using the array name. If we want we can use a pointer.
(1)
Siddharth_dixit said:
7 years ago
#include<stdio.h>
int main()
{
int a[5] = {10, 20, 30, 40, 50};
int j;
for(j=0; j<5; j++)
{
printf("%d\n", a[j]);
a[j]++;
}
return 0;
}
int main()
{
int a[5] = {10, 20, 30, 40, 50};
int j;
for(j=0; j<5; j++)
{
printf("%d\n", a[j]);
a[j]++;
}
return 0;
}
(1)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers