
- Forum
- Programming Talk
- C and C++
- Help to Resolve Error
Help to Resolve Error
This is a discussion on Help to Resolve Error within the C and C++ forums, part of the Programming Talk category; I am getting error when I tried to compile my below simple program in C. #include <stdio.h> main() { int ...
-
Help to Resolve Error
I am getting error when I tried to compile my below simple program in C.
#include <stdio.h>
main()
{
int a=5,b;
b=a++++2;
printf("a=%d b=%d",a,b);
}
I could not understand the reason to resolve the error. Kindly help me out.
-
It would be helpful to answer and resolve the error if you could place the exact error you are getting when you compile the above code.
-
The exact error that I got when I compiled my above program was as below:
Error message: Lvalue required in function main
I could not understand the meaning of this error. Kindly help me to resolve the error.
-
Before resolving the error you must first understand what is Lvalue which is displayed in error message. Lvalue refers to the variable whose values can change and this is placed to the left of assignment operator. There is another variable called rvalue which is in contrast to the Lvalue. The value of rvalue cannot change and this is placed to the right of assignment operator.
Now coming to your program you have statement as
b=a++++2;
In the above a++++2 is expanded as compiler as a++ ++2
In this a++ is fine but ++2 is wrong since ++ cannot be applied to constants and so you have the error as Lvalue required in function main. So remove the constant and make that as a variable and your problem would be resolved.
-
Sponsored Ads

Reply With Quote





