473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

What is the output of this program?

What will OUTPUT of this Program ?
Expand|Select|Wrap|Line Numbers
  1.  #include<stdio.h>
  2. main()
  3. {
  4.     int i=1,a=1;
  5.     i = ++i * ++i * ++i * ++i;
  6.     a = ++a + a++ + --a + a++;
  7.     printf("Value of i - %d\n",i);
  8.     printf("Value of a - %d\n",a);
  9. }
Please Explain this..
Sep 3 '07 #1
2 1222
weaknessforcats
9,208 Expert Mod 8TB
Firstly, you have psoted this in the C/C++ Articles forum. Please do not do that. Questions are to be posted in the C/C++ forum.

Secondly, the output is indeterminate. That is, it will vary based on compiler.

This is due to code like this:
i = ++i * ++i * ++i * ++i;
The variable i is being modified more than once in the same statement. The compiler is not bound to evaluate this in any particular order. Some compilers may go right to left while others go left ot right while others may do the ++ first (since it has precedence) and then do the multiply.
Sep 3 '07 #2
JosAH
11,448 Expert 8TB
Secondly, the output is indeterminate. That is, it will vary based on compiler.
Even worse: it's not just implementation defined, it is even undefined behaviour
which means that even for a single compiler implementation the results may differ.

kind regards,

Jos
Sep 3 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Qiangning Hong | last post by:
I decide to seperate my data collection routine from my data analysis and storage program to a seperate process, so I try to use the new subprocess model in Python 2.4. The main program spawns...
25
by: Nitin Bhardwaj | last post by:
Well, i'm a relatively new into C( strictly speaking : well i'm a student and have been doing & studying C programming for the last 4 years).....and also a regular reader of "comp.lang.c" I...
1
by: noleander | last post by:
Hi. I've got a C++ program written in Visual C++ 2003. The program is trivial, created with the Program-creation wizard: used the .NET "Form" template. The program has a trivial...
24
by: kalamantina | last post by:
#include "stdafx.h" #include <stdio.h> #define output( x ) printf( #x "\r\n" );fflush( stdout ) class CMyBase { public: CMyBase() { output( CMyBase() ); f(*this);
4
by: Jackie | last post by:
Hi, all, I want to get the information of the professors (name,title) from the following link: "http://www.economics.utoronto.ca/index.php/index/person/faculty/" Ideally, I'd like to have a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.