LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-08-2007, 06:51 AM   #1
ricka343
Member
 
Registered: Jun 2006
Posts: 54

Rep: Reputation: 15
how does cout works under different compilers


can anyone explain this
how different compilers r working

#include<iostream.h>
int main()
{
int i = 5;
cout<<i++<<i++<<++i<<++i;
cin>>i;
return 0;
}


outputs:
dev c++ : 5689
fedora core 6: g++ : 8799
fedora core 6: c++ :8799




#include<stdio.h>

int main()
{
int i = 5;
printf("%d\n%d\n%d\n%d\n",i++,i++,++i,++i);
scanf("%d",&i);
return 0;
}


outputs:

dev c: 8776

fedora core 6: gcc: 8799

fedora core 6: cc : 8799

Last edited by ricka343; 06-08-2007 at 07:08 AM.
 
Old 06-08-2007, 07:16 AM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Code:
<i++<<i++<<++i<<++i;
This is undefined behaviour and it is completely up to the implementation what the output is.
 
Old 06-08-2007, 07:27 AM   #3
ricka343
Member
 
Registered: Jun 2006
Posts: 54

Original Poster
Rep: Reputation: 15
but can u explain how thy r workin i mean how each is workin
 
Old 06-08-2007, 08:51 AM   #4
Indiestory
Member
 
Registered: Aug 2006
Location: Aberdeen, Scotland
Distribution: OpenBSD
Posts: 164
Blog Entries: 1

Rep: Reputation: 30
I have no idea what is happening there, don't think i seeing the point of the program properly, but it might help to know that cc normally is normally a symlink to the system compiler, in this case it seems gcc
 
Old 06-11-2007, 03:58 AM   #5
ricka343
Member
 
Registered: Jun 2006
Posts: 54

Original Poster
Rep: Reputation: 15
still not solved

The o/p for the c++ prog is 8776 in suse linux with g++ and c++ compilers.
plz explain all these cases if anybody can
 
Old 06-11-2007, 11:18 AM   #6
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Quote:
Originally Posted by ricka343
still not solved ...
plz explain all these cases if anybody can
Simple it is "...undefined behaviour..."
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cin/cout part of c or just c++ true_atlantis Programming 4 02-25-2006 06:54 PM
cout conversion to binary... audibel Programming 3 03-12-2005 07:06 AM
undefined symbol cout Tazzie76 Linux - Software 8 12-10-2004 02:09 PM
c++ cout not working :( Longinus Programming 10 08-01-2004 07:32 PM
cout queues miguetoo Programming 4 03-17-2004 02:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration