Exforsys

Online Training

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> ...


Go Back   Exforsys > Programming Talk > C and C++

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-26-2007, 10:54 PM
Senior Member
 
Join Date: Apr 2006
Posts: 122
rachelle is on a distinguished road
Smile 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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-28-2007, 03:13 AM
Senior Member
 
Join Date: Apr 2006
Posts: 144
caradoc is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-28-2007, 03:34 AM
Senior Member
 
Join Date: Apr 2006
Posts: 122
rachelle is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-28-2007, 04:03 AM
Senior Member
 
Join Date: Apr 2006
Posts: 144
caradoc is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
Error Message Rahulbatra ASP 1 05-24-2007 04:37 PM
web.config gives error if i store string that contin "&" character in appSettings mahehs_k_anjani Microsoft .NET 2 09-06-2006 06:21 AM
Comp.Sys.Acorn.FAQ part 2 of 4 Paul Vigay Tech FAQ 0 05-31-2004 09:00 PM
Apple II Csa2 FAQs: Error List, Part 8/25 rubywand@swbell.net Tech FAQ 0 05-04-2004 10:01 AM
Comp.Sys.Acorn.FAQ part 2 of 4 Paul Vigay Tech FAQ 0 04-30-2004 09:00 PM


All times are GMT -4. The time now is 01:08 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.