Can you correctly identify the output of the following program,
without compiling it?
#include <stdio.h>
int main( void )
{
int a=1;
int b=0;
int foo=10+a?1:0+b? 1:0;
printf( "%d\n", foo );
return 0;
}
Let's just say that I wish I had opened my desktop C references BEFORE
compiling and checking in certain changes I made. D'oh!
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome. 5 1208
Christopher Benson-Manica wrote: Can you correctly identify the output of the following program, without compiling it?
#include <stdio.h>
int main( void ) { int a=1; int b=0; int foo=10+a?1:0+b? 1:0; printf( "%d\n", foo ); return 0; }
Let's just say that I wish I had opened my desktop C references BEFORE compiling and checking in certain changes I made. D'oh!
My initial guess was 1 [and I checked] and I questioned myself thinking 11.
This is why god invented () btw. Write it as
int foo = (10+a)?1:(0+b?1 :0);
It becomes much clearer.
Tom
Christopher Benson-Manica wrote: Can you correctly identify the output of the following program, without compiling it?
Yes. :-)
#include <stdio.h>
int main( void ) { int a=1; int b=0; int foo=10+a?1:0+b? 1:0; printf( "%d\n", foo ); return 0; }
Let's just say that I wish I had opened my desktop C references BEFORE compiling and checking in certain changes I made. D'oh!
Wrong, huh? ;-)
Cheers!
Rich
On Fri, 13 Aug 2004 15:55:15 +0000 (UTC), Christopher Benson-Manica
<at***@nospam.c yberspace.org> wrote in comp.lang.c: Can you correctly identify the output of the following program, without compiling it?
#include <stdio.h>
int main( void ) { int a=1; int b=0; int foo=10+a?1:0+b? 1:0; printf( "%d\n", foo ); return 0; }
Let's just say that I wish I had opened my desktop C references BEFORE compiling and checking in certain changes I made. D'oh!
Don't have to. The programmer who wrote that on my team would be
warned the first time. Transferred or fired if it happened a second
time.
--
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.l earn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jack Klein wrote: On Fri, 13 Aug 2004 15:55:15 +0000 (UTC), Christopher Benson-Manica <at***@nospam.c yberspace.org> wrote in comp.lang.c:
Can you correctly identify the output of the following program, without compiling it?
#include <stdio.h>
int main( void ) { int a=1; int b=0; int foo=10+a?1:0+b? 1:0; printf( "%d\n", foo ); return 0; }
Let's just say that I wish I had opened my desktop C references BEFORE compiling and checking in certain changes I made. D'oh!
Don't have to. The programmer who wrote that on my team would be warned the first time. Transferred or fired if it happened a second time.
<facetious>
Wouldn't you expect your programmers to understand operator precedence?
</facetious>
<reality>
You are too kind.
</reality>
--ag
--
Artie Gold -- Austin, Texas
20050120->44
On Fri, 13 Aug 2004 15:55:15 +0000 (UTC), Christopher Benson-Manica
<at***@nospam.c yberspace.org> wrote: Can you correctly identify the [result of] int foo=10+a?1:0+b? 1:0;
Which is why to achieve what you wanted you should have done
int foo = 10+!!a+!!b;
which is read in "English"(? ) as ten plus "absolutely the truth value
of a" plus similarly for b <G> <G> <G up SHRT_MAX>.
- David.Thompson1 at worldnet.att.ne t This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Glutinous |
last post by:
Trying to learn php, and came across
=&
as in
$form =& $HTTP_POST_VARS;
I can't find any reference to =&, with no success in searching for a
definition (as though it's _so_ obvious it doesn't need explanation).
|
by: Sims |
last post by:
Hi,
I recall a function that would tell me how long it took to generate an
output.
But for the life of me I cannot remember it.
Dow anybody know it? Or do I have to write something myself, (using time?).
Sims
|
by: Jeff_Relf |
last post by:
Hi Tom, You showed: <<
private const string PHONE_LIST =
"495.1000__424.1111___(206)564-5555_1.800.325.3333";
static void Main( string args ) {
foreach (string phoneNumber in Regex.Split (PHONE_LIST, "_+")) {
Console.WriteLine (phoneNumber); } }
Output:
495.1000
|
by: Neil Zanella |
last post by:
OK, this time the compiler's got me a little bit puzzled, simply because it is
doing something I am not expecting. My understanding, according to the
documentation of std::vector<>::resize(), is that when you specify a
second argument the number of elements specified in the first
argument is each in turn set to the second argument.
void...
|
by: yee young han |
last post by:
I need a fast data structure and algorithm like below condition.
(1) this data structure contain only 10,000 data entry.
(2) data structure's one entry is like below
typedef struct _DataEntry_
{
char szInput;
char szOutput;
int iSum;
| |
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);
|
by: aboood |
last post by:
Hi guys
Could any one tell me what does that code do please? in pseudo-code
#include <fstream.h>
#include <iostream.h>
bool differsByOneDigit ( int , int );
void outputResults ( ofstream & , int * , int , bool );
|
by: mahesh |
last post by:
Hi all,
I have following code that is supposed to increase the power by
specified value.
int main()
{
system("cls");
int i, exponent;
double base;
double new_base=0.0;
|
by: Philluminati |
last post by:
I have a Perl SOAP Server which returns this SOAP Message when
invoked:
<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xsi="http://
www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://
schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/
XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/...
|
by: Yee.Chuang |
last post by:
When I began to learn C, My teacher told me that pointer is the most
difficult part of C, it makes me afraid of it. After finishing C
program class, I found that all the code I wrote in C contains little
pointers, obviously I avoid using them.
A few days ago when I was reading a book about programming, I was told
that pointers are the very...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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...
|
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...
|
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...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |