473,320 Members | 1,832 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,320 software developers and data experts.

Output undefined?

no
main()
{
int i;
printf("%d %d",i++,++i);
}

Is the output undefined?

int main #include crap etc. is understood.
Nov 13 '05 #1
6 1510
On Wed, 01 Oct 2003 16:53:56 +0200, n wrote:

int i;
printf("%d %d",i++,++i); Is the output undefined?

Yes because you have never given i a value.

And that's before considering in which order i++ and ++i will be evaluated.

--
NPV
"Linux is to Lego as Windows is to Fisher Price." - Doctor J Frink

Nov 13 '05 #2
"Nils Petter Vaskinn" <no@spam.for.me.invalid> wrote:
On Wed, 01 Oct 2003 16:53:56 +0200, n wrote:
int i;
printf("%d %d",i++,++i);

Is the output undefined?


Yes because you have never given i a value.

And that's before considering in which order i++ and ++i will be evaluated.


Order is immaterial; the mere occurence of them both together between
sequence points invokes undefined behaviour.

If either of you had read the FAQ, you'd have known this:
<http://www.eskimo.com/~scs/C-faq/q3.2.html>.

Richard
Nov 13 '05 #3
On Wed, 01 Oct 2003 16:53:56 +0200, no@no.no wrote in comp.lang.c:
main()
{
int i;
printf("%d %d",i++,++i);
}

Is the output undefined?

int main #include crap etc. is understood.


Yes, even if you initialized I with a value. There is no sequence
point in the evaluation of arguments to functions, so your code
modifies i twice without an intervening sequence point.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #4
In <pa****************************@spam.for.me.invali d> "Nils Petter Vaskinn" <no@spam.for.me.invalid> writes:
On Wed, 01 Oct 2003 16:53:56 +0200, n wrote:

int i;
printf("%d %d",i++,++i);
Is the output undefined?


Read the FAQ!
Yes because you have never given i a value.

And that's before considering in which order i++ and ++i will be evaluated.


The evaluation order does NOT matter. What matters is the lack of a
sequence point between these two expressions. So, instead of having an
unspecified output (assuming a properly initialised i) we have undefined
behaviour for the whole program. The FAQ clearly explains these issues!

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #5
no@no.no wrote:
int main #include crap etc. is understood.


It would have taken less typing to just to do it right in the first
place.

Brian Rodenborn
Nov 13 '05 #6
Default User <fi********@company.com> scribbled the following:
no@no.no wrote:
int main #include crap etc. is understood.
It would have taken less typing to just to do it right in the first
place.


I agree. I detect a shade of DAISNAID. Oh, sorry, forgot that
abbreviations are frowned upon here. "Do As I Say, Not As I Do".

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"You have moved your mouse, for these changes to take effect you must shut down
and restart your computer. Do you want to restart your computer now?"
- Karri Kalpio
Nov 13 '05 #7

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

Similar topics

3
by: Mike Conmackie | last post by:
Greetings, I am trying to create a node in the output tree using a variable. Here are some fragments that I hope will explain the problem better. <xsl:stylesheet...
54
by: bnp | last post by:
Hi, I took a test on C. there was an objective question for program output type. following is the program: main() { char ch; int i =2;
14
by: grocery_stocker | last post by:
If go like the following: #include <stdlib.h> void *test_me(int a) { int *m; m = &a; } main(void){
5
by: Kuku | last post by:
Would the following program give the same output at all times int main(int argc, char *argv) { strcpy(argv, "Hello"); strcpy(argv,"Good Morning"); printf("%s\n%s\n",argv,argv); return 0; }
22
by: Jaspreet | last post by:
I was recently asked this question in an interview. Unfortunately I was not able to answer it and the interviewer made a decision on my C strengths (or weekness) based on this single question and...
10
by: weichaoliu | last post by:
I know that this problem is concerned to GCC. But I hope somebody here can tell me some detailed things about why. The version of g++ I'm using is: g++ (GCC) 3.4.4 (mingw special). The code is:...
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);
13
by: Logan Lee | last post by:
Hi. I've written a small program to learn to write in C. But unfortunately the output is all jumbled up and not nice. /* read_file.c The whole point of this code is to read the entire content...
46
by: suresh | last post by:
Hi, For this code snippet, I get the following output, which I am unable to understand. (2^31 = 2147483648) cout<< -2147483648 << endl; cout << numeric_limits<int>::min() <<',' <<...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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)...
0
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...
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.