473,587 Members | 2,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unexpected result

hi
look at this code

include <stdio.h>
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;
printf("%d %d",i,j);
return 0;
}

acc. to me the values of i & j are 27,5 respectively & rightly so as i
ran this on turbo c++ compiler but if i ran this on lcc-win32 compiler
i got 32 & 5 for i & j respectively.
why this is so

Mar 8 '06 #1
62 3739
hi anshu
it all compiler depenedent
in lcc-win32 compiler
first the code run on right to left
means i=4*4*2
it give 32 for i
but in turboc compiler it execute code left to right and take big value
among it i.e. 3
so thats y its give 27.
bye
Ankur

ashu wrote:
hi
look at this code

include <stdio.h>
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;
printf("%d %d",i,j);
return 0;
}

acc. to me the values of i & j are 27,5 respectively & rightly so as i
ran this on turbo c++ compiler but if i ran this on lcc-win32 compiler
i got 32 & 5 for i & j respectively.
why this is so


Mar 8 '06 #2
ashu wrote:
hi
look at this code

include <stdio.h>
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;


Undefined behaviour: see the FAQ.

(Informally speaking, you update j three times in random order;
why do you expect the result to make sense? Except it's worse
than that.)

--
Chris "sparqling" Dollin
"Who do you serve, and who do you trust?"
Mar 8 '06 #3
Hi geeks,
Please tell me which book gives the complete
detail of dynamic memory management in C and C++.

Mar 8 '06 #4
ashu wrote:
hi
look at this code

include <stdio.h>
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;
printf("%d %d",i,j);
return 0;
}

acc. to me the values of i & j are 27,5 respectively & rightly so as
i ran this on turbo c++ compiler but if i ran this on lcc-win32
compiler i got 32 & 5 for i & j respectively. why this is so


This is a frequently asked question.

Please read http://c-faq.com/expr/
Mar 8 '06 #5
"ashu" <ri*********@ya hoo.com> writes:
include <stdio.h>
Copy-and-paste carefully; you missed the '#'.
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;
printf("%d %d",i,j);
return 0;
}


Undefined behavior. Read section 3 of the comp.lang.c FAQ,
<http://www.c-faq.com/>.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 8 '06 #6
novice wrote:
Hi geeks,
Please tell me which book gives the complete
detail of dynamic memory management in C and C++.

This has nothing to do with OP's question and should have been posted as
a new thread; not a reply to an existing one.

Google is a great place to find the information you are looking for
since I'm not sure what you mean by "dynamic memory management in c". As
far as C++ goes, you want comp.lang.c++ which is down the all first door
on the right. If you have a question which is specific to *c* then by
all means ask here (by posting in a new thread of course) and I'm sure
someone here would be happy to help you.

Joe
Mar 8 '06 #7
i dont my version of compiler but the result on my system was 27 &5
respectively

Mar 8 '06 #8
srikanth wrote:
i dont my version of compiler but the result on my system was 27 &5
respectively


Result of what? See below.

Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
Mar 8 '06 #9
On 2006-03-08, srikanth <ad********@gma il.com> wrote:

i dont my version of compiler but the result on my system was 27 &5
respectively


Please include context, by properly quoting the relevant parts of the
post you are replying to, so that people will understand what you are
talking about.

--
John Tsiombikas (Nuclear / Mindlapse)
nu*****@siggrap h.org
http://nuclear.demoscene.gr/
Mar 8 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
51386
by: sky2070 | last post by:
Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ')' in c:\inetpub\wwwroot\session.php on line 19 can anyone tell me what is wrong with this code??? <? // Define the Session class class Session { // Define the properties:
2
2880
by: Salim | last post by:
Hi people, keep getting this errorParse error: parse error, unexpected T_STRING in order_fns.php line 91. the code is below for the file and I've indicated line 91 <?php function process_card($card_details) { // connect to payment gateway or // use gpg to encrypt and mail or // store in DB if you really want to
6
19019
by: Ehartwig | last post by:
I recently created a script for user verification, solved my emailing issues, and then re-created the script in order to work well with the new PHP 5 that I installed on my server. After submitting user information into my creation script, I get the following error from the page that is suppose to insert the user data into the database, create a code, then send an email out for verification. Parse error: parse error, unexpected $end in...
5
13997
by: devereaux | last post by:
I'm trying to run a script and it's throwing the following error: Parse error: syntax error, unexpected T_OBJECT_OPERATOR in openfile.php on line 41 Here is the openfile.php file and I have bolded line 41. Any ideas/help would be greatly appreciated! <?php /* This file is responsible for the download of the files
13
3589
by: bintom | last post by:
I ran the following simple code in C++ and got unexpected results: float f = 139.4; cout << f; Output: 139.399994;
2
3423
by: =?Utf-8?B?QXJtaW4gR2FsbGlrZXI=?= | last post by:
Hi I've got an unexpected error in a unit test. I want to test a activity from Windows Workflow Foundation (WF). First, I executed the test outside of the activity just in the test-init method. In this case all works fine: public void TestInitialize() {
11
2923
by: JRough | last post by:
I'm trying to use output buffering to cheat so i can print to excel which is called later than this header(). header("Content-type: application/xmsdownload"); header("Content-Disposition: attachment; header("Pragma: no-cache"); header("Expires; 0"); print "$header\n$data";
14
5494
riverdale1567
by: riverdale1567 | last post by:
Hi I am a newbie trying to get some of my first code working, yada yada yada. I have a drop down box which chooses a state then takes the post data to 'processform2.php' to use that to pull up all the rows which have the corresponding state. I am getting this 'Parse error: syntax error, unexpected T_STRING in /home/attorney/public_html/' on line 13 <? $username="XXXXXXXX"; $password="XXXXXX"; $database="XXXXXXXX";
14
3591
by: Padfoot153 | last post by:
Hey, I'm getting the error: Parse error: syntax error, unexpected T_VARIABLE in /Users/Oscar/AwesomeSongz/userCake/profile.php on line 7 with this code <?php require_once("models/config.php"); function signinTimeStamp()
0
7854
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
7978
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.