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 3 of 7.
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
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)
Aim said:
1 decade ago
Here printf statement display address of memory location so when we do a++ is increment the address value but here left side any variable is not available to take it. So error is LValue required
Aditya reja said:
1 decade ago
The name of An Array is automatically constant pointer (i.e. cannot be alter) that always points to its 0th element. Due to its constant nature ++ or -- operators can't be apply to array's name.
Manoj S said:
11 months ago
The array name is also a pointer.
But it is a constant pointer, which means it can't be modified. So, we need an LValue(Left-hand value) to make it possible for traversal.
i.e: int *ptr = a;
But it is a constant pointer, which means it can't be modified. So, we need an LValue(Left-hand value) to make it possible for traversal.
i.e: int *ptr = a;
(1)
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.
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).
Traian said:
6 years ago
L - Value means an object that has an identifiable location in the memory(has an address) Ex: var a;
R - Value means an object with no identifiable location in the memory Ex: (a+b);
R - Value means an object with no identifiable location in the memory Ex: (a+b);
(7)
POOJA said:
1 decade ago
Very simple logic.
a is an array.
We can't perform following operations on array:
a++;
a--;
a+=2;
....
If pointer to an array will be there then we can perform above operations.
a is an array.
We can't perform following operations on array:
a++;
a--;
a+=2;
....
If pointer to an array will be there then we can perform above operations.
Rajendra Patil said:
1 decade ago
Expressions that refer to memory locations are called "l-value" expressions.
The term "r-value" is sometimes used to describe the value of an expression
The term "r-value" is sometimes used to describe the value of an expression
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers